Ajax四步操作

來源:互聯網
上載者:User

標籤:http   io   ar   os   sp   strong   on   cti   ad   

第一步得到(XMLHttpRequest)
function creatXMLHttpRequest(){
try{
return new XMLHttpRequest();
} catch(e){
try{
return new ActiveXObject(Msxml2.XMLHTTP);
}catch{
try{
return new ActiveXObject(Microsoft.XMLHTTP);
}catch(e){
alert("你的瀏覽器不支援AJax")
throw e;
}
}
}

第二步開啟與伺服器串連
var xmlHttp = creatXMLHttpRequest();
xmlHttp.open();
用來建立與伺服器的串連有三個參數
請求方式GET或POST
url:指定伺服器資源
第三個參數如果為true則非同步
第三步發送請求
xmlHttp.send(null):如果不給可能會造成部份瀏覽器無法發送!
> 參數:就是請求體內容!如果是GET請求,必須給出null。

第四步
擷取請求狀態
xmlHttp.onreadystatuschange="myfunction";
得到xmlHttp的狀態
var state = xmlHttp.readyState();
得到伺服器的響應狀態嗎
ar status = xmlHttp.status();
*得到伺服器的響應內容
var content = xmlHttp.response.Texxt;//文字格式設定內容
var content = xmlHttp.response.XML;//xml的內容
function myfunction(){
if(state == 4&&status==200){

}
}

Ajax四步操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.