編程學習網 > 編程教程 > AJAX 教程
2015
10-13

XHR 響應

清華大佬耗費三個月吐血整理的幾百G的資源,免費分享!....>>>

AJAX - 服務器 響應


服務器響應

如需獲得來自服務器的響應,請使用 XMLHttpRequest 對象的 responseText 或 responseXML 屬性。

屬性 描述
responseText 獲得字符串形式的響應數據。
responseXML 獲得 XML 形式的響應數據。


responseText 屬性

如果來自服務器的響應并非 XML,請使用 responseText 屬性。

responseText 屬性返回字符串形式的響應,因此您可以這樣使用:

實例

document.getElementById("myDiv").innerHTML=xmlhttp.responseText;



responseXML 屬性

如果來自服務器的響應是 XML,而且需要作為 XML 對象進行解析,請使用 responseXML 屬性:

實例

請求 cd_catalog.xml 文件,并解析響應:

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;

掃碼二維碼 獲取免費視頻學習資料

編程學習