🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #258

AJAX 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;

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

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();

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();

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();

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

AJAX Response – FAQs

Quick answers about learning AJAX Response in JavaScript.

This free note from CodingNow 2.0 explains AJAX Response in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including AJAX Response, is 100% free with no signup required.
With focused practice, most students grasp AJAX Response in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now