LLLLLLL Posted September 11, 2017 Share Posted September 11, 2017 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? Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/ Share on other sites More sharing options...
requinix Posted September 11, 2017 Share Posted September 11, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551137 Share on other sites More sharing options...
LLLLLLL Posted September 11, 2017 Author Share Posted September 11, 2017 (edited) 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 September 11, 2017 by timneu22 Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551140 Share on other sites More sharing options...
requinix Posted September 11, 2017 Share Posted September 11, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551143 Share on other sites More sharing options...
LLLLLLL Posted September 12, 2017 Author Share Posted September 12, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551182 Share on other sites More sharing options...
requinix Posted September 12, 2017 Share Posted September 12, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551184 Share on other sites More sharing options...
LLLLLLL Posted September 12, 2017 Author Share Posted September 12, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551198 Share on other sites More sharing options...
requinix Posted September 12, 2017 Share Posted September 12, 2017 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 Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551199 Share on other sites More sharing options...
Solution LLLLLLL Posted September 12, 2017 Author Solution Share Posted September 12, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551200 Share on other sites More sharing options...
Jacques1 Posted September 12, 2017 Share Posted September 12, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551201 Share on other sites More sharing options...
requinix Posted September 12, 2017 Share Posted September 12, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551202 Share on other sites More sharing options...
LLLLLLL Posted September 12, 2017 Author Share Posted September 12, 2017 (edited) 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 September 12, 2017 by timneu22 Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551204 Share on other sites More sharing options...
Sepodati Posted September 12, 2017 Share Posted September 12, 2017 (edited) Doesn't .post() parse the JSON itself to determine whether the call was a success or not? (Edit: Req already said that, actually.) Edited September 12, 2017 by Sepodati Quote Link to comment https://forums.phpfreaks.com/topic/304948-uncaught-syntaxerror-unexpected-end-of-input-chrome-error/#findComment-1551205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.