problem with eval() - localhost vs. webserver
function handleReceive() {
if (receiveReq.readyState == 4) {
var chat_div = document.getElementById('div_chat');
var response = eval("(" + receiveReq.responseText + ")");
.....
}
}
on localhost server the line var response = eval("(" + receiveReq.responseText + ")");
works fine
, but on server (for example 000webhosting.com) the code brokes here.
I try to check with alert().
On local server alert(response);
returns: [object Object]
,
but on webserver I got nothing, the sc开发者_开发技巧ript stops with executing here.
I try to return chat_div and it's ok. But var response
don't work, just as any other line after.
Can anyone help me with this?
If it works on localhost, but fails on a webserver, check if request-URL is not hard-coded to localhost absolute path.
If request URL is correct, just check what is in receiveReq.responseText
in both cases. If you are using PHP for your server scripts, the problem may be that your code generates warnings or notices and the webserver is configured to display them while your localhost is not.
But you are also right saying that problem is about eval()
, because as @AlienWebguy stated, the problem is the very fact of using it here. I'm sure there's a better solution.
精彩评论