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();
            }
        }
    }
}
复制代码

 

posted @   Jinsuo  阅读(84)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示