خصوصیات پاسخ سرور
Property | Description |
---|---|
responseText | get the response data as a string |
responseXML | get the response data as XML data |
ویژگی پاسخText
responseText
اموال را برمی گرداند پاسخ سرور به عنوان یک رشته جاوا اسکریپت، و شما می توانید آن را بر این اساس استفاده کنید:
مثال
document.getElementById("demo").innerHTML = xhttp.responseText;
خاصیت پاسخ XML
شی X 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();