ajax

var xhr = createStandardXHR() || createActiveXHR();
var state = 0;
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
state = 1;
typeof cb == 'function' && cb(undefined, dataType == 'json' ? JSON.parse(xhr.responseText) : xhr.responseText);
} else {
typeof cb == 'function' && cb(xhr.error);
state = 2;
}
}
setTimeout(function () {
if (state == 0) {
xhr.abort();
typeof cb == 'function' && cb('timeout');
}
}, 8000);
xhr.open('GET', url, true);
xhr.send();
原文地址:https://www.cnblogs.com/Mr-Joe/p/4665183.html