Hello I noticed that this simple code doesn't work the way it is supposed to work...
function test() {
$.ajax( {
'url' : 'test/GameConfiguration.json',
'dataType' : 'json',
data : {
a : 'aaa'
},
cache : false,
method : 'get',
timeout : 10000, //10 secs of timeout
success : function(data, textStatus, XMLHttpRequest) {
console.log("success");
if (data == null)
console.log("it's not a real success");
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
console.log("error: " + textStatus);
}
});
}
The test has been run on localhost, I mean: I load the page, I shut down the local webserver, then I fire the request (via a simple button with onclick pointing to this function). Error doesn't ever get called, what I get is to have the success handler called and it has textStatus = "success" and data = null. I even notice that the request times out long before 10 seconds. This happens on Firefox (last version), Chrome (last version) and Safari 5. Why this? Is it due to the fact I'm working on localhost?
I forgot to tell: THE Request isn't cached. In fact both firebug and Chrome dev tools show the request to fail.
Big update
This behaviour is related to the use of localhost. In fact if I load this page from another collegue PC and before triggering the request I disconnect my PC from the network, I correctly get the error handler fired with timeout as status. I think this is a bug of jQuery. It will make me hard to test the timeout errors :(
Guys from jQuery forums say this is due to the way the network stack aborts the connection, given that the host is localhost. I tested this on Windows 7 only. If you feel like testing this on other systems and you can work out some jQuery internals, report to this post at the jQuery forums: