js-ajax-04
function ajax(url,fnSucc,fnError) {
if (window.XMLHttpRequest) {
var httpRequest = new XMLHttpRequest();
} else {
var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
//2 连接服务器
httpRequest.open('GET', url, true);
//3 发送请求
httpRequest.send();
//4 接受结果
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
if (httpRequest.status === 200) {
fnSucc && fnSucc(httpRequest.responseText);
} else {
fnError && fnError();
}
}
}
}