Skip to content Skip to sidebar Skip to footer

JQuery AJAX 200 Status, Yet Mysterious Syntax Error

I have a status 200 being returned when I'm using jQuery AJAX. However, I am also getting a syntax error from somewhere. I am posting to PHP like this: function submit_order(orderI

Solution 1:

It is your error handler that gets fired and logs:

  • xhr.status (200)
  • thrownError (the syntax error)

Note that $.ajax with dataType: json will fire the error handler even if the server returns 200 OK but the response is invalid JSON. The syntax error is not in your JavaScript code but in the JSON. Identify where the < is coming from and make sure that your PHP script is sending valid JSON.

Tip: open the console and look at the network tab; all XHRs are logged there along with headers and body.


Solution 2:

200 - Is an Ok response by a server http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

You have a syntax error in your response server returns invalid json

As your PHP code seams fine, there must be something else. Syntax error or your framework returns json wrapped in html ...

Use proper tools to see what is returned by server. (firebug on firefox/ developer tools on chrome)

In your image you see 0: "<" That means that returned string starts with < - That means it is html that got returned.

Looks like you use chrome. Go to your "network" tab in chrome an you should be able to see raw response for your request.

so it is a php error:

$sector_index is not itarable. Can you var_dump it to see. what it is?


Solution 3:

It looks like <?=time()?> isn't getting processed. Alert the URL before you post to it for verification.


Post a Comment for "JQuery AJAX 200 Status, Yet Mysterious Syntax Error"