我在我的MooTools脚本中运行一个AJAX调用,这在Firefox中工作得很好,但在Chrome中,我得到了一个未捕获的SyntaxError:意外令牌:错误,我不能确定为什么。注释掉代码来确定坏代码在哪里不会产生任何结果,我认为这可能是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();
  });
});

当前回答

我得到这个错误,因为我在脚本标签中缺少类型属性。

最初我使用,但当我在脚本标记内添加类型属性时,我的问题就解决了

其他回答

对于那些在AngularJs 1.4.6或类似版本中遇到过这种情况的人来说,我的问题是angular找不到我的模板,因为我提供的templateUrl (path)中的文件找不到。我只需要提供一个可到达的路径,问题就解决了。

看到红色错误

未捕获SyntaxError:意外的令牌<

在Chrome开发人员的控制台选项卡中是响应体中的HTML指示。

您实际看到的是浏览器对意想不到的顶部行<!DOCTYPE html>从服务器。

反复面对JS问题,我正在我的xblock包上应用Ckeditor。如果有人帮助我,请告诉我。使用OpenEdx, Javascript, xblock

xblock.js:158 SyntaxError: Unexpected token '=>'
at eval (<anonymous>)
at Function.globalEval (jquery.js:343)
at domManip (jquery.js:5291)
at jQuery.fn.init.append (jquery.js:5431)
at child.loadResource (xblock.js:236)
at applyResource (xblock.js:199)
at Object.<anonymous> (xblock.js:202)
at fire (jquery.js:3187)
at Object.add [as done] (jquery.js:3246)
at applyResource (xblock.js:201) "SyntaxError: Unexpected token '=>'\n    at eval (<anonymous>)\n    at Function.globalEval (http://localhost:18010/static/studio/common/js/vendor/jquery.js:343:5)\n    at domManip (http://localhost:18010/static/studio/common/js/vendor/jquery.js:5291:15)\n    at jQuery.fn.init.append (http://localhost:18010/static/studio/common/js/vendor/jquery.js:5431:10)\n    at child.loadResource (http://localhost:18010/static/studio/bundles/commons.js:5091:27)\n    at applyResource (http://localhost:18010/static/studio/bundles/commons.js:5054:36)\n    at Object.<anonymous> (http://localhost:18010/static/studio/bundles/commons.js:5057:25)\n    at fire (http://localhost:18010/static/studio/common/js/vendor/jquery.js:3187:31)\n    at Object.add [as done] (http://localhost:18010/static/studio/common/js/vendor/jquery.js:3246:7)\n    at applyResource (http://localhost:18010/static/studio/bundles/commons.js:5056:29)"

在我的情况下,这是一个错误的url(不存在),所以也许你的“发送”在第二行应该是其他…

如果没有任何意义,这个错误也可能是由嵌入在html/javascript中的PHP错误引起的,比如下面这个

<br />
<b>Deprecated</b>:  mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in <b>C:\Projects\rwp\demo\en\super\ge.php</b> on line <b>54</b><br />
var zNodes =[{ id:1, pId:0, name:"ACE", url: "/ace1.php", target:"_self", open:true}

不是PHP插入到html中的代码中的<br />等导致了错误。要修复这类错误(抑制警告),请在开始时使用此代码

error_reporting(E_ERROR | E_PARSE);

要查看,右键单击页面,“查看源代码”,然后检查完整的html以发现此错误。