最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught SyntaxError: Unexpected token ILLEGAL for Chrome Browser - Stack Overflow

programmeradmin0浏览0评论

toggle.js

var $jq = jQuery.noConflict();
$jq(document).ready(function(){

    $jq('.isAdd').hide();

    $jq("#Add_category").change(function(){          
        var value = $jq("#Add_category option:checked").val();
        var theDiv = $jq(".isAdd");

        theDiv.slideToggle("slow");
    });
});​

In console I had:

Uncaught SyntaxError: Unexpected token ILLEGAL

For Firefox it's works fine, but not for Chrome and Chromium for Ubuntu.

toggle.js

var $jq = jQuery.noConflict();
$jq(document).ready(function(){

    $jq('.isAdd').hide();

    $jq("#Add_category").change(function(){          
        var value = $jq("#Add_category option:checked").val();
        var theDiv = $jq(".isAdd");

        theDiv.slideToggle("slow");
    });
});​

In console I had:

Uncaught SyntaxError: Unexpected token ILLEGAL

For Firefox it's works fine, but not for Chrome and Chromium for Ubuntu.

Share Improve this question asked Oct 14, 2011 at 6:50 kwaigonkwaigon 8153 gold badges12 silver badges31 bronze badges 5
  • what is the HTML markup? – Igor Dymov Commented Oct 14, 2011 at 6:57
  • Here it is: pastie.org/2693372 – kwaigon Commented Oct 14, 2011 at 7:33
  • On what line is the error thrown? – Šime Vidas Commented Oct 14, 2011 at 11:34
  • Btw the above code works just fine: jsfiddle.net/simevidas/ENxyL – Šime Vidas Commented Oct 14, 2011 at 12:28
  • Possible duplicate of No visible cause for "Unexpected token ILLEGAL" – Michał Perłakowski Commented Dec 29, 2015 at 15:18
Add a comment  | 

3 Answers 3

Reset to default 14

There is an invisible character following the last }); of your last line. When I pasted it into my editor, it appeared as a ..

View your code in an editor capable of displaying non-printable characters with some kind of symbol, or view it in a hex editor.

To summarize the solution to problem with "Unexpected Token ILLEGAL":

ILLEGAL means strictly Syntax Error.

The Fix

Install HxD Editor (recommended) and open your file in it. You can detect where exactly the error is occuring by detecting unusual . (as it happened with me), with the code's HEX representation. Save and replace the file.

@TiSer: please check your code for invisible white space chars, on document ready handler is not the problem here, it was the illegal token direct after them – Irishka Oct 14 '11 at 13:57

yeap, it's right! Incredible - one small symbol and all JS code fell. :) – TiSer Oct 17 '11 at 8:50

$jq(document).ready(...); is causing this error Chrome

move your jQuery script to the bottom before < /body > tag

EDIT: check for white spaces

发布评论

评论列表(0)

  1. 暂无评论