AJAX XMLHttpRequest server response
AJAX - Server response
Server response
To get the response from the server, use the responseText or responseXML property of the XMLHttpRequest object.
| Property | Description |
|---|---|
| responseText | Get the response data in string format. |
| responseXML | Get the response data in XML format. |
responseText attribute
Use the responseText attribute if the response from the server is not XML.
The responseText attribute returns the response as a string, so you can use it like this:
instance
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
Try it »
responseXML attribute
If the response from the server is XML and needs to be parsed as an XML object, use the responseXML attribute:
instance
Request cd_catalog.xml file 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
"
"
;
}
document
.
getElementById
(
"
myDiv
"
)
.
innerHTML
=
txt
;
Try it »