首页 > 试题广场 >

ajax 的过程

1. 创建XMLHttpRequest对象,也就是创建一个异步调用对象
2. 创建一个新的HTTP请求,并指定该HTTP请求的方法、URL及验证信息
3. 设置响应HTTP请求状态变化的函数
4. 发送HTTP请求
5. 获取异步调用返回的数据
6. 使用JavaScript和DOM实现局部刷新
发表于 2015-07-27 15:01:28 回复(1)
更多回答
1.新建一个request对象
2.request.open("url","get"/"post",false);
3.onreadyState监听
4.设置http响应头信息
5.如果是post必须发送request.send(null//这里不能为空);
6.接收返回response,刷新页面
发表于 2016-08-28 11:03:35 回复(0)
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
    if (xhr.readyState === 4)
        if(xhr.status === 200)
            // do something
}
xhr.open('get/post/put...', url, true/false)     // arg[0]: method; arg[1]: url; arg[2]: async or not
xhr.send(null)     // send data or null

发表于 2018-02-25 15:44:50 回复(0)
// 1.创建一个XML实例对象 
var xhr = new XMLHttpRequest() 
// 2.定义请求的方法我这里用get,url已经验证信息
xhr.open('GET', 'http://127.0.0.1:8000/server', true/false )
// 3.发送HTTP请求 
xhr.send(null) 
//4.设置响应HTTP请求状态变化的函数 
xhr.onreadystatechange = function(){
    if(xhr.readyState ===4){
        if (xhr.status >=200 && xhr.status<300) {
            console.log(666); 
        }
    } 
}

编辑于 2023-04-07 19:35:05 回复(0)
<p>新建一个xmlhttprequest对象</p><p>新建一个http包含请求头,url</p><p>返回一个状态及资源</p>
发表于 2020-08-29 17:17:09 回复(0)

1.创建XMLHttpRequest对象 也就是创建异步调用对象

2.创建http请求 设置http请求的方式 url 验证信息

3.设置响应http请求变化的函数

4.发送http请求

5.获取异步调用返回的数据

6.采用javascript和dom实现页面局部刷新

编辑于 2019-10-15 19:18:39 回复(0)
1. 创建XMLHttpRequest对象,也就是创建一个异步调用对象 2. 创建一个新的HTTP请求,并指定该HTTP请求的方法、URL及验证信息 3. 设置响应HTTP请求状态变化的函数 4. 发送HTTP请求 5. 获取异步调用返回的数据 6. 使用JavaScript和DOM实现局部刷新
发表于 2019-05-03 13:54:41 回复(0)
var xhr=new XMLHttpRequest();
    xhr.onreadystatechange=function(){
        if(xhr.readyState===4){
            if(xhr.status===200){
                doResponse(xhr.responseText);
            }
        }
    }
    xhr.open('GET','URL',true);
    xhr.send(null);
    
    xhr.open('POST','URL',true);
    setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send('k=v&k=v');

发表于 2017-12-10 22:28:25 回复(0)
这里说的不全面,如果请求方法是post,还需要封装请求的数据data
发表于 2016-08-22 18:00:30 回复(1)