Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome: Uncaught SyntaxError: Unexpected end of input

People also ask

How do you fix uncaught SyntaxError unexpected end of JSON input?

You can solve the "Unexpected end of JSON input" error in the following 3 ways: wrap your parsing logic in a try/catch block. make sure to return a valid JSON response from your server. remove the parsing logic from your code if you are expecting an empty server response.

What does unexpected end of input mean in JavaScript?

Usually the Uncaught SyntaxError: Unexpected end of input error in JavaScript occurs due to missing parentheses, bracket, or quote. However, it can also happen when we try to parse an empty JSON. It could be that the extension that you are using is trying to run a javascript code where either of the above is true.


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("");

I get this error when I have ommitted a closing brace character (})in JavaScript code. Check that your braces are properly balanced.