JavaScript error (Uncaught SyntaxError: Unexpected end of input)

后端 未结 11 2081
天命终不由人
天命终不由人 2020-11-27 10:30

I have some JavaScript code that works in FireFox but not in Chrome or IE.

In the Chrome JS Console I get the follow error:

\"Uncaught Synta

相关标签:
11条回答
  • 2020-11-27 10:41

    In my case, I was trying to parse an empty JSON:

    JSON.parse(stringifiedJSON);
    

    In other words, what happened was the following:

    JSON.parse("");
    
    0 讨论(0)
  • 2020-11-27 10:41

    In my case, it was caused by a missing (0) in javascript:void(0) in an anchor.

    0 讨论(0)
  • 2020-11-27 10:45

    http://jsbeautifier.org/ is helpful to indent your minified JS code.

    Also, with Google Chrome you can use "pretty print". See the example screenshot below showing jquery.min.js from Stack Overflow nicely indented right from my browser :)

    enter image description here

    0 讨论(0)
  • 2020-11-27 10:46

    I think it could be almost any javascript error/typing error in your application. I tried to delete one file content after another and finally found the typing error.

    0 讨论(0)
  • 2020-11-27 10:48

    I also got this error pointing to the end of the last script block on a page, only to realize the error was actually from clicking on an element with a onclick="pagename" instead of onclick="window.location='pagename'". It's not always a missing bracket!

    0 讨论(0)
  • 2020-11-27 10:51

    I got this error when I was trying to write a javascript bookmarklet. I couldn't figure out what was causing it. But eventually I tried URL encoding the bookmarklet, via the following website: http://mrcoles.com/bookmarklet/ and then the error went away, so it must have been a problem with certain characters in the javascript code being interpreted as special URL control characters.

    0 讨论(0)
提交回复
热议问题