天天看點

ajax post useragent,ajax異步請求post方式

//建立浏覽器對象

function createXhr(){

//判定浏覽器類型處理第一種方法

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);