AJAX XMLHttpRequest Server Response
-- Not just learning technology, but dreams too!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
AJAX Tutorial
AJAX Tutorial AJAX Intro AJAX Examples XHR Creating Object XHR Request XHR Response XHR readyState AJAX ASP/PHP AJAX Database AJAX XML AJAX Examples AJAX JSON Examples Fetch API
AJAX β onreadystatechange Event
AJAX - Server Response
Server Response
To obtain a response from the server, please use the responseText or responseXML properties of the XMLHttpRequest object.
| Property | Description |
|---|---|
| responseText | Get response data in string format. |
| responseXML | Get response data in XML format. |
responseText Property
If the response from the server is not XML, please use the responseText property.
The responseText property returns the response in string format, so you can use it like this:
Example
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
responseXML Property
If the response from the server is XML, and needs to be parsed as an XML object, please use the responseXML property:
Example
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.childNodes.nodeValue + "<br>; }document.getElementById("myDiv").innerHTML=txt;
YouTip