Chrome: Uncaught SyntaxError: Unexpected end of input

When loading my page in Google Chrome, I get a vague error in the console:

Uncaught SyntaxError: Unexpected end of input

I have no idea what is causing it. How would I go about debugging this error?


This particular error is one annoying fact about V8. In most cases your JavaScript is broken in some way. For example missing a } or something like that.

Example given, this will yield "Unexpected end of input" too:

eval('[{"test": 4}') // notice the missing ]

But the root cause of the problems seems to be that the requested JSON url has a Content-Type of text/html which Chrome apparently tries to parse as HTML, which then results in the unexpected end of input due to the fact that the included image tags are being parsed.

Try setting the Content-Type to text/plain I think it should fix the issues.

Nonetheless, V8 could do a better Job about telling one exactly where the input ended unexpectedly.


Try Firebug for Mozilla - it will show the position of the missing } .

http://getfirebug.com/


See my case on another similar question:

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

JSON.parse(stringifiedJSON);

In other words, what happened was the following:

JSON.parse("");
链接地址: http://www.djcxy.com/p/45974.html

上一篇: webkit中的意外标记ILLEGAL

下一篇: Chrome:未捕获SyntaxError:意外的输入结束