0

I've got a webpage with an AJAX request using jQuery and dataType=json

$.ajax({
 type: "POST",
 url: 'api/',
 data: post,
 success: function(data) {}
 dataType: 'json',
 error: function(jqXHR, textStatus, errorThrown) {
  var message = myprint(errorThrown)+myprint(textStatus)+myprint(jqXHR);
  // myprint is a custom print function
  alert(message);
 }
}

About 1% of the time, I got this alert :

{}
"parsererror"
{
 "readyState": 4,
 "responseText": "{\"results\":[\"TEST1\",\"TEST2\"],\"time\":\"0,123\"}",
 "status": 200,
 "statusText": "OK"
}

Clearly there is no parseerror. Do you have any idea that I might check ? Thank you.

3
  • you perhaps do not get json from php/the server.
    – loveNoHate
    Commented Oct 5, 2014 at 17:55
  • @DOCASAREL The response is shown in the responseText: line. It sure looks like valid JSON.
    – Barmar
    Commented Oct 5, 2014 at 17:58
  • Is it the exact same action which returns both a correct JSON response, and the error (at different times)? Or is there maybe some other function that is called server-side which may be causing the response to be parsed as a string and not as JSON?
    – Guy Passy
    Commented Oct 5, 2014 at 18:03

1 Answer 1

0

Error: "showing-json parse error" that mean: data format response from server incorrect.

In client, you set dataType is 'json' but into data response is not json data or may be xml (i not sure, you should check again).

2
  • He's printing the response from the server, since it's included in the jqXHR object.
    – Barmar
    Commented Oct 5, 2014 at 17:56
  • Where do you see a < in the response text?
    – Barmar
    Commented Oct 5, 2014 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.