I get a parse error when using jQuery to load some JSON data. Here's a snippet of my code:
jQuery.ajax({
dataType: "json",
success: function (json)
{
jQuery.each(json, function ()
{
alert(this["columnName"]);
});
}
});
I get no errors when parsing a non-empty JSON object. So my guess is that the problem is with my serializer.
Question is: how do I format an empty JSON object which jQuery won't consider malformed?
This is what I've tried so far, with no success:
{[]}
{[null]}
{}
{null}
{"rows": []}
{"rows": null}
{"rows": {}}
UPDATE:
I can understand that I've been somewhat vague--let me try and clarify:
Parsing of the JSON object is not the issue here--JQuery is - I think.
jQuery throws a parse-error (invokes the error function). It seems like jQuery's internal JSON validation is not accepting any of the before mentioned objects. Not even the valid ones.
Output of the error function is:
XMLHttpRequest:
XMLHttpRequest readyState=4 status=200textStatus:
parsererrorerrorThrown:
undefined
This goes for all of the before mentioned objects.
The solution is to return a status code of 204 rather than 200 from the server, 204 is "no content" and it will return success while not trying to invoke the parser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With