AJAX 服務(wù)器 響應(yīng)
服務(wù)器響應(yīng)
如需獲得來(lái)自服務(wù)器的響應(yīng),請(qǐng)使用 XMLHttpRequest 對(duì)象的 responseText 或 responseXML 屬性。
屬性 | 描述 |
---|---|
responseText | 獲得字符串形式的響應(yīng)數(shù)據(jù)。 |
responseXML | 獲得 XML 形式的響應(yīng)數(shù)據(jù)。 |
responseText 屬性
如果來(lái)自服務(wù)器的響應(yīng)并非 XML,請(qǐng)使用 responseText 屬性。
responseText 屬性返回字符串形式的響應(yīng),因此您可以這樣使用:
實(shí)例文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-426740.html
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
responseXML 屬性
如果來(lái)自服務(wù)器的響應(yīng)是 XML,而且需要作為 XML 對(duì)象進(jìn)行解析,請(qǐng)使用 responseXML 屬性:
實(shí)例
請(qǐng)求 cd_catalog.xml 文件,并解析響應(yīng):文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-426740.html
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;
到了這里,關(guān)于Ajax XHR響應(yīng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!