WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AJAX - Server Response


Server Response

To get the reaction from a server, utilize the responseText or responseXML property of the XMLHttpRequest object.

Property Description
responseText get the reaction information as a string
responseXML get the reaction information as XML data

The responseText Property

If the reaction from the server isn't XML, utilize the responseText property.

The responseText property restores the reaction as a string, and you can utilize it accordingly:

Example

document.getElementById("demo").innerHTML = xhttp.responseText;

The responseXML Property

If the reaction from the server is XML, and you need to parse it as a XML object, utilize the responseXML property:

Example

Request the document cd_catalog.xml and parse the response:

xmlDoc = xhttp.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("ARTIST");
for (I = 0; I < x.length; i++) {
  txt += x[i].childNodes[0].nodeValue + "<br>";
  }
document.getElementById("demo").innerHTML = txt;