Jump to content


Photo

"Uncaught SyntaxError: Unexpected end of input" Chrome error

ajax

Best Answer LLLLLLL, 12 September 2017 - 07:19 PM

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.

Go to the full post


  • Please log in to reply
12 replies to this topic

#1 LLLLLLL

LLLLLLL
  • Members
  • PipPipPip
  • Advanced Member
  • 308 posts

Posted 11 September 2017 - 07:27 PM

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?



#2 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,135 posts
  • LocationWA

Posted 11 September 2017 - 07:37 PM

The JSON blob that's returned is obviously valid...

It's not obvious to me. In fact that's where I think the problem is.
The Reimann Zeta Function Trolley Problem | "Stop! You're spoiling my unjustified indignation!"

#3 LLLLLLL

LLLLLLL
  • Members
  • PipPipPip
  • Advanced Member
  • 308 posts

Posted 11 September 2017 - 07:51 PM

But the JSON blob can be parsed, so it's not an invalid blob. Besides that, nothing has interacted with "data" at this point, so where would an error come from?


Edited by timneu22, 11 September 2017 - 07:52 PM.


#4 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,135 posts
  • LocationWA

Posted 11 September 2017 - 08:29 PM

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.
The Reimann Zeta Function Trolley Problem | "Stop! You're spoiling my unjustified indignation!"

#5 LLLLLLL

LLLLLLL
  • Members
  • PipPipPip
  • Advanced Member
  • 308 posts

Posted 12 September 2017 - 12:42 PM

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

 

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



#6 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,135 posts
  • LocationWA

Posted 12 September 2017 - 01:16 PM

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.
The Reimann Zeta Function Trolley Problem | "Stop! You're spoiling my unjustified indignation!"

#7 LLLLLLL

LLLLLLL
  • Members
  • PipPipPip
  • Advanced Member
  • 308 posts

Posted 12 September 2017 - 03:22 PM

Yes, I put a breakpoint there -- which means BEFORE that line has executed -- and the error already occurred. Proceeding past parse() is not an issue. It is a proper JSON object.



#8 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,135 posts
  • LocationWA

Posted 12 September 2017 - 04:26 PM

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
The Reimann Zeta Function Trolley Problem | "Stop! You're spoiling my unjustified indignation!"

#9 LLLLLLL

LLLLLLL
  • Members
  • PipPipPip
  • Advanced Member
  • 308 posts

Posted 12 September 2017 - 07:19 PM   Best Answer

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.



#10 Jacques1

Jacques1
  • Members
  • PipPipPip
  • Turtles all the way down
  • 4,222 posts

Posted 12 September 2017 - 07:41 PM

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.



#11 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,135 posts
  • LocationWA

Posted 12 September 2017 - 08:05 PM

: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 Reimann Zeta Function Trolley Problem | "Stop! You're spoiling my unjustified indignation!"

#12 LLLLLLL

LLLLLLL
  • Members
  • PipPipPip
  • Advanced Member
  • 308 posts

Posted 12 September 2017 - 09:45 PM

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, 12 September 2017 - 09:47 PM.


#13 Sepodati

Sepodati
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts
  • LocationCaro, MI

Posted 12 September 2017 - 09:51 PM

Doesn't .post() parse the JSON itself to determine whether the call was a success or not?

(Edit: Req already said that, actually.)

Edited by Sepodati, 12 September 2017 - 09:52 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users