Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

javascript - 未捕获的SyntaxError:意外的令牌:(Uncaught SyntaxError: Unexpected token :)

I am running an AJAX call in my MooTools script, this works fine in Firefox but in Chrome I am getting a Uncaught SyntaxError: Unexpected token : error, I cannot determine why.(我在我的MooTools脚本中运行一个AJAX调用,这在Firefox中运行良好但在Chrome中我得到一个Uncaught SyntaxError: Unexpected token :错误Uncaught SyntaxError: Unexpected token :错误,我无法确定原因。)

Commenting out code to determine where the bad code is yields nothing, I am thinking it may be a problem with the JSON being returned.(注释掉代码来确定坏代码的位置什么都没有产生,我想这可能是返回JSON的问题。) Checking in the console I see the JSON returned is this:(检查控制台我看到返回的JSON是这样的:)
{"votes":47,"totalvotes":90}

I don't see any problems with it, why would this error occur?(我没有看到任何问题,为什么会出现这种错误?)

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();
  });
});
  ask by trobrock translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Seeing red errors(看到红色错误)

Uncaught SyntaxError: Unexpected token <(未捕获的SyntaxError:意外的令牌<)

in your Chrome developer's console tab is often an indication of 301 Redirects that could be caused by having a strange rule in your .htaccess file.(在Chrome开发人员的控制台标签中,通常会显示301重定向 ,这可能是由.htaccess文件中有一条奇怪的规则引起的。)

What you're actually seeing is your browser's reaction to the unexpected top line <!DOCTYPE html> from the server.(您实际看到的是您的浏览器对来自服务器的意外顶线<!DOCTYPE html>的反应。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...