我在我的 MooTools 脚本中运行 AJAX 调用,这在 Firefox 中运行良好,但在 Chrome 中我收到 Uncaught SyntaxError: Unexpected token :
error,我无法确定原因。注释掉代码以确定错误代码的位置不会产生任何结果,我认为这可能是返回 JSON 的问题。检查控制台我看到返回的 JSON 是这样的:
{"votes":47,"totalvotes":90}
我没有看到任何问题,为什么会出现这个错误?
vote.each(function(e){
e.set('send', {
onRequest : function(){
spinner.show();
},
onComplete : function(){
spinner.hide();
},
onSuccess : function(resp){
var j = JSON.decode(resp);
if (!j) return false;
var restaurant = e.getParent('.restaurant');
restaurant.getElements('.votes')[0].set('html', j.votes + " vote(s)");
$$('#restaurants .restaurant').pop().set('html', "Total Votes: " + j.totalvotes);
buildRestaurantGraphs();
}
});
e.addEvent('submit', function(e){
e.stop();
this.send();
});
});
原文由 trobrock 发布,翻译遵循 CC BY-SA 4.0 许可协议
我刚刚解决了这个问题。标准请求调用出现问题,所以这是我使用的代码:
如果有人知道为什么标准的 Request 对象给我带来了问题,我很想知道。