AJAX - ဆာဗာ တုံ့ပြန်မှု
ဆာဗာ တုံ့ပြန်မှု ဂုဏ်သတ္တိများ
Property | Description |
---|---|
responseText | get the response data as a string |
responseXML | get the response data as XML data |
တုံ့ပြန်မှုစာသားပိုင်ဆိုင်မှု
responseText
ပိုင်ဆိုင်မှုသည် ဆာဗာတုံ့ပြန်မှုကို JavaScript စာကြောင်းအဖြစ် ပြန်ပေးကာ ၎င်းကို လိုက်လျောညီထွေစွာ အသုံးပြုနိုင်သည် ။
ဥပမာ
document.getElementById("demo").innerHTML = xhttp.responseText;
တုံ့ပြန်မှုXML ပိုင်ဆိုင်မှု
XMLHttpRequest object တွင် in-built XML parser တစ်ခုရှိသည်။
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();