admin管理员组文章数量:1332389
I have a PHP script (fetchData.php) that fetches some data and outputs it to a page.
<?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"].";"));
?>
You can see the output here: .php I have another page that uses an XMLHttpRquest to get the response from fetchData.php Here's the JavaScript for it. It's supposed to take the response, and eval() it (to create an array called BWMFunction) then pass that array to another function I have. The Illegal token error occurs when I try to eval() the response.
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();
}
This is my first time on StackOverflow, so any help would be appreciated. I have googled around for quite a while now, but none of the answers helped me.
I have a PHP script (fetchData.php) that fetches some data and outputs it to a page.
<?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"].";"));
?>
You can see the output here: http://justicecraft/worldmap/fetchData.php I have another page that uses an XMLHttpRquest to get the response from fetchData.php Here's the JavaScript for it. It's supposed to take the response, and eval() it (to create an array called BWMFunction) then pass that array to another function I have. The Illegal token error occurs when I try to eval() the response.
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();
}
This is my first time on StackOverflow, so any help would be appreciated. I have googled around for quite a while now, but none of the answers helped me.
Share edited Feb 20, 2013 at 20:15 Robert Harvey 181k48 gold badges348 silver badges513 bronze badges asked Jan 8, 2012 at 21:35 Jacob BrunsonJacob Brunson 1,4924 gold badges24 silver badges37 bronze badges1 Answer
Reset to default 6You have invalid javascript returned from fetchData.php
which is why the eval
method crashes. Instead of \"
in the output you should have simple "
. I know strictly nothing about PHP but I am ready to bet some bucks that its the addslashes
function which is causing the damage. So maybe you could try something along the lines of:
echo($response["success"].";");
本文标签: xmlhttprequestJavascript Unexpected token ILLEGALStack Overflow
版权声明:本文标题:xmlhttprequest - Javascript Unexpected token ILLEGAL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742290576a2447718.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论