Easy Tutorial
❮ Ajax Asp Php Ajax Xmlhttprequest Create ❯

AJAX - Server Response


Server Response

To obtain the response from the server, use the responseText or responseXML property of the XMLHttpRequest object.

Property Description
responseText Gets the response data as a string.
responseXML Gets the response data as XML.

responseText Property

If the response from the server is not XML, use the responseText property.

The responseText property returns the response as a string, so you can use it like this:

Example


responseXML Property

If the response from the server is XML and needs to be parsed as an XML object, use the responseXML property:

Example

Request the 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 + "<br>";
}
document.getElementById("myDiv").innerHTML = txt;
❮ Ajax Asp Php Ajax Xmlhttprequest Create ❯