I have a Single Page javascript webapp that we rolled from scratch (I know I know)
We have a central set of ajax defaults that work as follows:
Model.defaultsLoader = function(message, config, callback, async, delay){
if(typeof delay === "undefined"){
delay = 3000;
}
var loader = new Loader(delay, message);
defaults = {
type: 'GET',
beforeSend: function(jqXHR){
var token = $("meta[name='csrf-token']").attr("content");
jqXHR.setRequestHeader("X-CSRF-Token", token);
},
success: function(response){
loader.stop();
if(callback){
callback(response);
}
},
error: function(jqXHR, textStatus, errorThrown ){
if (jqXHR.status === 401) {
document.location = "/";
}
else if(!death && jqXHR.status !== 200) {
loader.showError(textStatus + ": " + errorThrown);
Support.bugReport(
account.email + ', ' +
message + ': ' +
textStatus + ': ' +
errorThrown);
}
},
dataType: 'json',
async: async
};
for(var param in config){
defaults[param] = config[param];
}
return defaults;
};
The Problem I am running into is that recently we started having problems with 304 Not Modified responses from our back end ending up in the error handler rather than the success handler. The reason is 'parseerror'... For whatever reason JQuery is attempting to parse the response body from our server on a 304 response (which is "" aka nothing.) I know that an empty string is not valid json, but I don't understand why Jquery is trying to parse the empty string rather than loading the cached value... this is causing rather troublesome behavior on our production servers in certain circumstances.
I've included a screen shot of the dev console of a print out I did for the purposes of debugging. you'll have to excuse that it's unfolded minified code.
Edit: It also seems weird that the debugger is showing a response code of 200 while the chrome dev tools is showing a response code of 304.