AJAX - ServerResponse


Server Response

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

Property Description
responseText Get response data as a string.
responseXML Get 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

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

Try it Yourself »


responseXML Property

If the response from the server is XML, and you need to parse it as an XML object, use the responseXML property:

Example

Requestcd_catalog.xmlfile, 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;

Try it Yourself »
Other Extensions