ajax执行步骤

1、创建一个请求对象

  var xhr = new XMLHttpRequest()

2、发起链接

  xhr.open('GET','http://baidu.com')  三个参数   ①get或者post   ②请求地址   ③同步false或异步true  第三个参数可以不写默认为异步

3、监听响应

  xhr.oneradystatechange = function(){

    5、获取返回值

      if(xhr.status === 200 && xhr.readyState === 4){

        console.log(xhr.responseText)

      }

  }

4、发送请求

  xhr.send()

posted @ 2021-11-01 20:38  不知名的贺贺  阅读(141)  评论(0)    收藏  举报