var xhr;
if(window.XMLHttpRequest){
//兼容IE7+, Firefox, Chrome, Opera, Safari
xhr=new XMLHttpRequest();
}else {
// 兼容ie5,兼容ie6
xhr=new ActiveXObject("Microsoft.XMLHttp");
}
xhr.open("post","/bond/get",true);//建立连接
xhr.setRequestHeader('Content-Type','application/json');//post请求必须发送请求头。
xhr.send(JSON.stringify({userId:1,bondName:val,pageSize:20,pagumber:1}));//发送数据
xhr.onreadystatechange=function () {//监听状态
if(xhr.readyState==4){
if(xhr.status==200){
var data=JSON.parse(xhr.responseText);
}else {
alert("错误码"+xhr.status);
}
}else {
}
}
原生ajax的书写
最新推荐文章于 2024-05-06 19:57:53 发布