全栈:使用回调函数封装Ajax

 

封装Ajax

function myAjaxTool(url,cb){
    var xhr=new XMLHttpRequest()
    xhr.open("GET",url,true)
    xhr.send()
    xhr.onreadystatechange=function(){
        if(xhr.readyState==4&&xhr.status==200){
            cb(xhr.responseText)
        }
    }
}

 

使用封装的Ajax工具

function fn2(){
   var url2="http://192.168.10.4:8080/ajax"
   myjq(url2,(data)=>{
       console.log(data)
   })
}

 

posted on 2022-08-04 19:39  香香鲲  阅读(37)  评论(0)    收藏  举报