AJAX - استجابة الخادم
خصائص استجابة الخادم
Property | Description |
---|---|
responseText | get the response data as a string |
responseXML | get the response data as XML data |
خاصية responseText
تقوم responseText
الخاصية بإرجاع استجابة الخادم كسلسلة JavaScript ، ويمكنك استخدامها وفقًا لذلك:
مثال
document.getElementById("demo").innerHTML = xhttp.responseText;
خاصية responseXML
يحتوي كائن XMLHttpRequest على محلل XML مضمن.
تقوم responseXML
الخاصية بإرجاع استجابة الخادم ككائن XML DOM.
باستخدام هذه الخاصية ، يمكنك تحليل الاستجابة ككائن 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();