原生ajax

var xhr = new XMLHttpRequest()
 
 
xhr.onreadystatechange = function(){
   if(xhr.readyStatus === 4 && xhr.status == 200){
   console.log(
      xhr.responseText
         )
   }
}

 

xhr.open("POST",url,true)                     

xhr.send()

 

 

 

1. open 方法的第三个参数,如果是true代表是异步(默认),如果是false代表是同步 会阻塞住

2. readyStatus:

 

posted @ 2020-06-12 01:27  hh9515  阅读(74)  评论(0)    收藏  举报