AJAX - Sunucu Yanıtı
Sunucu Yanıtı Özellikleri
Property | Description |
---|---|
responseText | get the response data as a string |
responseXML | get the response data as XML data |
ResponseText Özelliği
Özellik responseText
, sunucu yanıtını bir JavaScript dizesi olarak döndürür ve buna göre kullanabilirsiniz:
Örnek
document.getElementById("demo").innerHTML = xhttp.responseText;
tepkiXML Özelliği
XMLHttpRequest nesnesinin yerleşik bir XML ayrıştırıcısı vardır.
Özellik responseXML
, sunucu yanıtını bir XML DOM nesnesi olarak döndürür.
Bu özelliği kullanarak yanıtı bir XML DOM nesnesi olarak ayrıştırabilirsiniz:
Örnek
cd_catalog.xml dosyasını isteyin ve yanıtı ayrıştırın:
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();
Sunucu Yanıt Yöntemleri
Method | Description |
---|---|
getResponseHeader() | Returns specific header information from the server resource |
getAllResponseHeaders() | Returns all the header information from the server resource |
getAllResponseHeaders() Yöntemi
Yöntem getAllResponseHeaders()
, sunucu yanıtından tüm başlık bilgilerini döndürür.
Örnek
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML =
this.getAllResponseHeaders();
}
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
getResponseHeader() Yöntemi
Yöntem getResponseHeader()
, sunucu yanıtından belirli başlık bilgilerini döndürür.
Örnek
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML =
this.getResponseHeader("Last-Modified");
}
xhttp.open("GET", "ajax_info.txt");
xhttp.send();