Hi,
i use the following code to send an ajax-request every 3 seconds:
var refreshId = setInterval(function() {
$.ajax({
async: true,
url: 'gohere',
dataType: 'text',
cache: false,
timeout: 5000,
success: function(result, textStatus, XMLHttpRequest) {
alert('textStatus: ' + textStatus + ",\nXHR.readyState: " + XMLHttpRequest.readyState + ",\nXHT.status: " + XMLHttpRequest.status);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('textStatus: ' + textStatus + ",\nXHR.readyState: " + XMLHttpRequest.readyState + ",\nXHT.status: " + XMLHttpRequest.status);
}
});
}, 3000);
The problem is, that even if the home-server is not accessible (eg not connected to the LAN) the success-function will be called instead of the error-function with a "timeout"-status (tested on Ubuntu 10.04 with FireFox 3.6.7).
(Without periodic requests it will work fine: On timeouts the error-function is called with the correct 'timeout'-statusText.)
The success-alert-function will show the following text on timeouts:
textStatus: success, XHR.readyState: 4, XHR.status: 0So i need to use the XHR.status-value, which should be 200 on success, to determine errors. Is this the normal behaviour or did i something wrong?