我在我的 MooTools 脚本中运行 AJAX 调用,这在 Firefox 中工作正常,但在 Chrome 中我收到Uncaught SyntaxError: Unexpected token :错误,我无法确定原因。注释掉代码以确定错误代码的位置不会产生任何结果,我认为这可能是返回 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();
  });
});