1航背,創(chuàng)建XMLhttprequest對象,異步調用對象
2巫击,創(chuàng)建一個新的HTTP請求,并指定該HTTP請求的方法禀晓、URL及驗證信息
3精续,設置響應http請求狀態(tài)變化的函數
4,發(fā)送HTTP請求
5粹懒,獲取異步調用返回的數據
6重付,使用js或dom局部更新數據
var xmlhttp;
//判斷瀏覽器類型
if (window.XMLHttpRequest){
? ?xmlhttp = new XMLHttpRequest();
} else {
? xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//發(fā)送請求, async為true, 規(guī)定響應處于 onreadystatechange 事件中就緒狀態(tài)時執(zhí)行
xmlhttp.onreadystatechange=function(){
? ? if (xmlhttp.readyStatus==4 && xmlhttp.status==200){
? ? ? ? document.getElementById('mydiv').innerHTML=xmlhttp.responseText;
? ? }
}
xmlhttp.open(method, url, async);
xmlhttp.send(string);
//添加http頭,在send中添加你希望發(fā)送的信息
xmlhttp.setRequestHeader(header, value);
xmlhttp.send("fname=Lee&lname=anne");