Property |
Description |
responseText |
Retrieve the response data as a string. |
responseXML |
Retrieve the response data as XML. |
The responseText
property returns the server’s response as a JavaScript string, which can be used as needed.
document.getElementById(“demo”).innerHTML = xhttp.responseText; |
The XMLHttpRequest
object includes a built-in XML parser.
The responseXML
property returns the server’s response as an XML DOM object, which can then be parsed as an XML DOM object.
Request the cd_catalog.xml
file and parse the response.
const xmlDoc = xhttp.responseXML; const x = xmlDoc.getElementsByTagName(“ARTIST”); let txt = “”; for (let i = 0; i < x.length; i++) { txt += x[i].childNodes[0].nodeValue + “<br>”; } document.getElementById(“demo”).innerHTML = txt; xhttp.open(“GET”, “cd_catalog.xml”); xhttp.send(); |
Method |
Description |
getResponseHeader() |
Fetches specific header information from the server’s response. |
getAllResponseHeaders() |
Fetches all header information from the server’s response. |
The getAllResponseHeaders() method retrieves all header information from the server’s response.
const xhttp = new XMLHttpRequest(); xhttp.onload = function() { document.getElementById(“demo”).innerHTML = this.getAllResponseHeaders(); } xhttp.open(“GET”, “ajax_info.txt”); xhttp.send(); |
The getResponseHeader() method retrieves specific header information from the server’s response.
const xhttp = new XMLHttpRequest(); xhttp.onload = function() { document.getElementById(“demo”).innerHTML = this.getResponseHeader(“Last-Modified”); } xhttp.open(“GET”, “ajax_info.txt”); xhttp.send(); |