其他分享
首页 > 其他分享> > js 写ajax

js 写ajax

作者:互联网

    function   test(){
alert("123")
var xhr = new XMLHttpRequest();
//发送异步请求
var url='/efficiency/web/selectDeptByCity';
xhr.open("GET",url,true);
//发送请求
xhr.send();
xhr.onreadystatechange=function () {
// 通信成功时,状态值为4
if (xhr.readyState === 4){
if (xhr.status === 200){
alert(xhr.responseText);
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
}

原文https://blog.csdn.net/u012060033/article/details/89958461

标签:function,console,js,xhr,ajax,var,responseText,alert
来源: https://www.cnblogs.com/cuiguangpeng/p/13524679.html