AJAX - Server Response

JavaScript is the world's most popular programming language.
JavaScript is the programming language of the Web.
JavaScript is easy to learn.
This tutorial will teach you JavaScript from basic to advanced.
Post Reply
Guest

AJAX - Server Response

Post by Guest »

AJAX - Server Response


Server Response Properties


Property
Description


responseText
get the response data as a string


responseXML
get the response data as XML data



The responseText Property
The responseText property returns the server response as a
JavaScript string, and you can use it accordingly:

Example

document.getElementById("demo").innerHTML = xhttp.responseText;
Try it Yourself »


The responseXML Property
The XMLHttpRequest object has an in-built XML parser.
The responseXML property returns the server response as an XML DOM object.
Using this property you can parse the response as an XML DOM object:

Example
Request the file cd_catalog.xml 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.childNodes[0].nodeValue + "<br>";
}
document.getElementById("demo").innerHTML = txt;

xhttp.open("GET",
"cd_catalog.xml");xhttp.send();
Try it Yourself »








Server Response Methods


Method
Description


getResponseHeader()
Returns specific header information from the server resource


getAllResponseHeaders()
Returns all the header information from the server resource



The getAllResponseHeaders() Method
The getAllResponseHeaders() method returns all header information from the server response.

Example

const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
    document.getElementById("demo").innerHTML =
    this.getAllResponseHeaders();
}
xhttp.open("GET", "ajax_info.txt");
xhttp.send();

Try it Yourself »


The getResponseHeader() Method
The getResponseHeader() method returns specific header information from the server response.

Example

const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
    document.getElementById("demo").innerHTML =
    this.getResponseHeader("Last-Modified");
}
xhttp.open("GET", "ajax_info.txt");
xhttp.send();

Try it Yourself »














+1

Reference: https://www.w3schools.com/js/js_ajax_http_response.asp
Post Reply