美文网首页
ajax实现

ajax实现

作者: TRYao | 来源:发表于2018-07-23 23:21 被阅读0次
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
            if ((xhr.state >= 200 && xhr.state < 300)||xhr.status == 304) {
                alert(xhr.responseText)
            } else {
                alert('Request was unsuccessful:'+xhr.status);
            }
        }
    }
    xhr.open('get','example.txt',true);
    xhr.send(null);
    

    在接受到响应之前还可以调用abort()方法来取消异步请求。

    相关文章

      网友评论

          本文标题:ajax实现

          本文链接:https://www.haomeiwen.com/subject/texsmftx.html