Jump to content

"Uncaught SyntaxError: Unexpected end of input" Chrome error


Go to solution Solved by LLLLLLL,

Recommended Posts

I'm getting "Uncaught SyntaxError: Unexpected end of input" (VM4193:1) on this AJAX call:

  MakeRequest : function( blah, blah ) {
    
    $.post( blah-blah-url,
      obj,
      function( data ) {

      var result = null;
      try {							
      	result = JSON.parse( data );
      } catch (err) {

      }

      SOMETHING.HandleResult( result );
    })
    .fail( function() {

    });
  },

... the odd thing is, I get this error in Chrome before anything has actually happened in the result. What I mean is: when I put the breakpoint on result=null, the error happens right there. The parse() function has no error, so... what on earth is going on?

 

I'm not sure how to be any more clear on this or what to add. It's quite standard stuff. The JSON blob that's returned is obviously valid... so I wonder where that error is coming from?

So have you looked at the stack trace for the error yet?

 

But the JSON blob can be parsed, so it's not an invalid blob.

Says who? Where is the proof it was parsed correctly? You can't know because execution hasn't even gotten to that point.

 

Besides that, nothing has interacted with "data" at this point, so where would an error come from?

From jQuery recognizing the response as JSON and trying to decode it automatically.

You said you put a breakpoint on

var result = null;
and the error had already happened.

 

Look at the backtrace. Also try adding

dataType: "text"
to the .ajax options and see if the error moves to a different place.

You're contradicting yourself.

 

1. According to you,

Yes, I put a breakpoint there -- which means BEFORE that line has executed -- and the error already occurred.

the JSON has not been parsed yet at the time of the error.

 

2. Also according to you,

It gets parsed on the next line of code without issue.

it is a proper JSON object because it has been parsed, which would have happened before the error.

 

You can't have both. So pick:

a) The JSON is valid because the line of code that parses the JSON magically executed without you seeing it, or

b) The JSON may or may not be valid; you cannot tell because the line of code that parses the JSON has not magically executed without you seeing it

  • Solution

I'm tired of PHP Freaks. Too many people trying to show their arrogance and not help.

 

As I have stated, the error is before any parsing. The parsing is always successfu. The error occurs immediately when DATA has a value.  You're the only one mentioning magic. Nothing magic is happening.

 

I'm done with this thread. Getting no help and never will.

I'm tired of PHP Freaks.

 

Then go away. Your schtick of posting nonsense and then complaining about those who actually know what they're doing may have been funny for a while. But after 7 years, it's a rather lame routine.

 

Spend less time bitching and more time programming. Then you might actually get somewhere.

:psychic:

 

The JSON is not valid, and the error happens is because jQuery parsed it for you automatically. The exception backtrace would have told you as much, if you had bothered to look at it when I told you to 7 hours ago.

 

But whatever. Your code, your problem.

The JSON is valid. It gets parsed.

 

result = JSON.parse( data );

 

The only error is that Chrome shows an error PRIOR TO PARSING. But there is no error in the JSON, and nothing has interacted with "data".

Edited by timneu22
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.