5 ms·
"Prior to 1.9, an ajax call that expected a return data type of JSON or JSONP would consider a return value of an empty string to be a success case, but return
by jasonkostempski 14y ago
"Prior to 1.9, an ajax call that expected a return data type of JSON or JSONP would consider a return value of an empty string to be a success case, but return a null to the success handler or promise. As of 1.9, an empty string returned for JSON data is considered to be malformed JSON (because it is); this will now throw an error."
That one is gonna cause some headaches, I've abused this behavior for years, as recently as yesterday.
- dmethvin 14y agoSo your server returns an HTTP 200 with an empty response, and you process the `null` in your success handler? Do you really want a `null` returned? Is this a server you control, or is it some third-party service? Just curious about the use case and how widespread it might be.
- jasonkostempski 14y agoI was probably in control of all of them at some level but I either didn't think about it or didn't care enough. Sometimes I suck. Today I can start sucking a little less.
- k3n 14y agoIt sounds like you knew it was bad practice, and yet you did it anyways...?
- svachalek 14y agoThis confused me for a minute but I think I get it now -- it's referring to a response with zero length, not a response of two quote characters right?
- jasonkostempski 14y agoYes, but two quote characters on their own isn't valid JSON either so that'll error too, though I assume it already did.
- deltasquared 14y agoThis stuff never works happily. I don't really trust jQuery to handle JSON/JSONP properly. It is easy enough to drop back down to calling XMLHttpRequest by hand. Sample code is here, and changes to jQuery won't break it: http://stackoverflow.com/questions/5395118/jquery-1-5-json-error-invalid-label/5403755#5403755 http://stackoverflow.com/questions/5395118/jquery-1-5-json-e...
- kamjam 14y agoWhy did you not just specify the dataType in your ajax call? http://api.jquery.com/jQuery.ajax/#data-types http://api.jquery.com/jQuery.ajax/#data-types
- deltasquared 14y agoBecause was working with jQuery 1.5, and data-types showed up in 1.5.1