Web前端

Ajax学习笔记

2020-04-13  本文已影响0人  Jessy丶x

ajax是什么?

ajax过程

/** 1. 创建连接 **/
var xhr = null;
xhr = new XMLHttpRequest()
/** 2. 连接服务器 **/
xhr.open('get', url, true)
/** 3. 发送请求 **/
xhr.send(null);
/** 4. 接受请求 **/
xhr.onreadystatechange = function(){
    if(xhr.readyState == 4){
        if(xhr.status == 200){
            success(xhr.responseText);
        } else { 
            /** false **/
            fail && fail(xhr.status);
        }
    }
}

ajax 有那些优缺点?

优点:
缺点:
上一篇 下一篇

猜你喜欢

热点阅读