//1 創(chuàng)建對象
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject)
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
else if(widow.XMLHttpRequest)
xmlHttp = new XMLHttprequest();
}
//2建立請求
♠
var firstName = document.getElementById("firstName").value;
var url= "9-3.aspx?"+ new Date().getTime();
xmlHttp.open("GET",url+ "firstName=" + firstName ,ture)//ture表示異步 get方法在提交數(shù)據(jù)時候在queryString 中發(fā)送數(shù)據(jù)
♣
xmlHttp.open("POST",url);//第4步發(fā)送數(shù)據(jù)時候用xmlHttp.send(firstName)
//3異步對象鏈接服務(wù)器
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
var responseDiv = document.getElementById("serverResponse");//xmlHttp.responseText服務(wù)器的返回并賦值
responseDiv.innerHTML = decodeURI(xmlHttp.responseText); //解碼
}
//4數(shù)據(jù)發(fā)送
xmlHttp.send(null)
2步驟當(dāng)為post時候
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");