<script>
//创建浏览器对象
function createxhr(){
//判定浏览器类型处理第一种方法
/* var xhr;
var str=window.navigator.useragent;
if(str.indexof('msie')>0){
xhr=new activexobject('microsoft.xmlhttp');
}else{
xhr=new xmlhttprequest();
}
return xhr;
*/
try{
return new activexobject('microsoft.xmlhttp');
}catch(e){
}
try{
return new xmlhttprequest();
}catch(e){
}
};
//ajax post请求
var data="username=zs&&password=123456";
var xhr=createxhr();
xhr.onreadystatechange=function(){
if(xhr.readystate==4&&xhr.status==200){
};
}
xhr.open("post","/ajaxpost1");
xhr.setrequestheader('content-type','application/x-www-form-urlencoded')
xhr.send(data);
</script>
以上就是ajax异步请求post方式的详细内容。
