2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

ajax初步學(xué)習(xí)二

 rui5327 2012-08-30

獲得服務(wù)端的響應(yīng)信息,使用XMLHttpRequest 對象的 responseText 或者responseXML 屬性

Property財產(chǎn) Description描述
responseText 獲取響應(yīng)數(shù)據(jù)作為一個字符串
responseXML 得到的響應(yīng)數(shù)據(jù)作為XML數(shù)據(jù)


responseText屬性

如果服務(wù)端的響應(yīng)不是xml,就可以使用responseText 屬性。

responseText 屬性返回響應(yīng)信息是一個字符串document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

responseXML屬性

如果服務(wù)端響應(yīng)是xml,可以使用responseXML 屬性。

Request the file cd_catalog.xml and parse the response:

xmlDoc=xmlhttp.responseXML;
txt="";
x=xmlDoc.getElementsByTagName("ARTIST");
for (i=0;i<x.length;i++)
  {
  txt=txt + x[i].childNodes[0].nodeValue + "<br />";
  }
document.getElementById("myDiv").innerHTML=txt;

9.onreadystatechange事件

當(dāng)響應(yīng)發(fā)送到服務(wù)器,我們要在響應(yīng)結(jié)果的基礎(chǔ)上執(zhí)行一些動作,使用onreadystatechange事件

 onreadystatechange事件被觸發(fā),當(dāng)每次readyState變化時。

readyState屬性保存的是XMLHttpRequest對象的狀態(tài)

XMLHttpRequest對象的三個重要的屬性:

Property財產(chǎn) Description描述
onreadystatechange Stores a function (or the name of a function) to be called automatically each time the readyState property changes存儲函數(shù)(或一個函數(shù)的名稱)被自動調(diào)用,每次readyState屬性的變化
readyState 保存XMLHttpRequest的狀態(tài)。從0到4的變更:
0: request not initialized 0:請求未初始化
1: server connection established 1:服務(wù)器連接已建立
2: request received 2:接收到的請求
3: processing request 3:請求處理
4: request finished and response is ready 4:要求成品和響應(yīng)準(zhǔn)備
status狀態(tài) 200: "OK" 200:“OK”
404: Page not found 404:沒有發(fā)現(xiàn)

當(dāng)readyState為4和狀態(tài)是200,響應(yīng)已準(zhǔn)備就緒:

Example例子

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }

10.使用回調(diào)函數(shù)Callback Function

一個回調(diào)的函數(shù),被看過另一個函數(shù)的參數(shù)。如果程序當(dāng)中有多個ajax任務(wù),可以定義一個標(biāo)準(zhǔn)函數(shù),以便通用

function myFunction()
{
loadXMLDoc("ajax_info.txt",function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  });
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多