XMLHttpRequest的timeout在firefox<12 版本无效的,可以重写XMLHttpRequest的timeout对象
// snip
to = function() {
attempt++;
if( attempt < 5)
send();
else if( !silent) {
console.log("Request Timeout\nFailed to access "+url);
}
};
// snip
var send = function() {
if( loader && attempt != 0) {
loader.children[0].firstChild.nodeValue = "Error... retrying...";
loader.children[1].firstChild.nodeValue = "Attempt "+(attempt+1)+" of 5";
}
a = new XMLHttpRequest();
a.open("POST","/ajax/"+url,true);
a.onreadystatechange = rsc;
setTimeout(function () { /* vs. a.timeout */
if (a.readyState < 4) {
a.abort();
}
}, 5000);
a.onabort = to; /* vs. a.ontimeout */
a.setRequestHeader("Content-Type","application/json");
a.send(data);
console.log('HTTP Requesting: %s', url);
};