AJAX - सर्वर प्रतिक्रिया
सर्वर प्रतिक्रिया गुण
Property | Description |
---|---|
responseText | get the response data as a string |
responseXML | get the response data as XML data |
प्रतिक्रियापाठ संपत्ति
संपत्ति सर्वर प्रतिक्रिया को जावास्क्रिप्ट स्ट्रिंग के रूप में responseText
लौटाती है, और आप इसके अनुसार इसका उपयोग कर सकते हैं:
उदाहरण
document.getElementById("demo").innerHTML = xhttp.responseText;
प्रतिक्रिया एक्सएमएल संपत्ति
XMLHttpRequest ऑब्जेक्ट में एक इन-बिल्ट XML पार्सर है।
गुण सर्वर प्रतिक्रिया को XML DOM ऑब्जेक्ट के रूप में responseXML
लौटाता है।
इस संपत्ति का उपयोग करके आप प्रतिक्रिया को XML DOM ऑब्जेक्ट के रूप में पार्स कर सकते हैं:
उदाहरण
फ़ाइल cd_catalog.xml का अनुरोध करें और प्रतिक्रिया को पार्स करें:
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() | Returns specific header information from the server resource |
getAllResponseHeaders() | Returns all the header information from the server resource |
GetAllResponseHeaders () विधि
getAllResponseHeaders()
विधि सर्वर प्रतिक्रिया से सभी शीर्षलेख जानकारी लौटाती है ।
उदाहरण
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML =
this.getAllResponseHeaders();
}
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
getResponseHeader () विधि
getResponseHeader()
विधि सर्वर प्रतिक्रिया से विशिष्ट शीर्षलेख जानकारी लौटाती है ।
उदाहरण
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML =
this.getResponseHeader("Last-Modified");
}
xhttp.open("GET", "ajax_info.txt");
xhttp.send();