69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

AJAX XMLHttpRequest 服務(wù)器響應(yīng)

ajax - 服務(wù)器 響應(yīng)

服務(wù)器響應(yīng)

如需獲得來自服務(wù)器的響應(yīng),請使用 xmlhttprequest 對象的 responsetext 或 responsexml 屬性。

屬性 描述
responsetext 獲得字符串形式的響應(yīng)數(shù)據(jù)。
responsexml 獲得 xml 形式的響應(yīng)數(shù)據(jù)。

responsetext 屬性

如果來自服務(wù)器的響應(yīng)并非 xml,請使用 responsetext 屬性。

responsetext 屬性返回字符串形式的響應(yīng),因此您可以這樣使用:

實例

document.getelementbyid("mydiv").innerhtml=xmlhttp.responsetext;

嘗試一下 ?

responsexml 屬性

如果來自服務(wù)器的響應(yīng)是 xml,而且需要作為 xml 對象進(jìn)行解析,請使用 responsexml 屬性:

實例

請求 cd_catalog.xml 文件,并解析響應(yīng):

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)文章