1
我有一個PHP腳本(fetchData.php),它獲取一些數據並將其輸出到頁面。Javascript意外的令牌非法
<?php
require 'config.php';
require 'jsonapiSDK.php';
$api = new JSONAPI($ip_address, $jsonapi_port, $username, $password, $salt);
$response = $api->call('BWMFunction');
echo(addslashes($response["success"].";"));
?>
您可以在這裏看到的輸出:http://justicecraft.net/worldmap/fetchData.php 我有一個使用XMLHttpRquest擺脫fetchData.php 響應另一個頁面下面是JavaScript的它。它應該採取響應,並eval()它(創建一個名爲BWMFunction的數組),然後將該數組傳遞給我擁有的另一個函數。當我嘗試eval()響應時發生非法令牌錯誤。
function fetchData() {
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
res = xmlhttp.responseText;
alert(res);
eval(res);
generate(BWMFunction);
}
}
xmlhttp.open("GET", "fetchData.php", true);
xmlhttp.send();
}
這是我第一次在StackOverflow,所以任何幫助,將不勝感激。我已經搜索了很長一段時間,但沒有任何答案對我有幫助。
我認爲你的權利haha – 2012-01-08 21:40:16
哇,很明顯,但它的工作!這很諷刺,因爲我添加了addslashes(),因爲我試圖擺脫一個問題,但它一定是另一個問題!謝謝! – fruitcup 2012-01-08 21:43:03
@DrAgonmoray,如果這篇文章幫助你解決了你應該考慮的問題[標記爲答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work )點擊旁邊的勾號。 – 2012-01-08 21:48:31