I am upgrading from jQuery 1.3.2 to jQuery 1.5 and I can’t get JSON to parse. With $.ajax I am calling a php script that returns the following via the PHP json_encode method:
{"vErrorsFound":true,"vMessage":"Login Failed"}
I have tried simplifying the object to:
{"vErrorsFound":true} alone and {"vMessage":"Login Failed"} alone but I still get a parse Error from the ajax call.
Here’s the ajax call.
$.ajax({
url : "index_vld.php",
data: {Username: $("input[name=Username]").val(), Password: $("input[name=Password]").val()},
dataType: 'json',
success: function (data, textStatus, jqXHR)
{
alert(data);
},
error: function (jqXHR, textStatus, errorThrown)
{
alert(textStatus + ' ' + errorThrown);
}
});
I found out that JSON parsing is much stricter in the newer version of jquery however I cannot find out what’s wrong in this simple json object returned from the PHP script. I have also tried setting the content type of the php script to application/json without success.
The exception thrown reads: jQuery15045727721066214144_1298305275108 was not called.
Can’t upgrade to jQuery 1.5 before I solve this.
Thanks for your help.
I had the same behavior with my Ajax requests updating from jQuery 1.4.4 to 1.5.1. Alexey’s answer worked for the short term, but the Ajax rewrite in jQuery 1.5 makes that solution suboptimal for prolonged use.
If you are using jQuery + the jQuery Validation plugin and continue to experience this error, try grabbing the latest Validation source from https://github.com/jzaefferer/jquery-validation. I pulled the source, dropped into my app, and now I’m getting much more consistent Ajax responses.