AJAX - XMLHttpRequest Object
AJAX ၏သော့ချက်မှာ XMLHttpRequest object ဖြစ်သည်။
XMLHttpRequest Object
ခေတ်မီဘရောက်ဆာများအားလုံးသည် XMLHttpRequest အရာဝတ္တုကို ပံ့ပိုးပေးသည်။
XMLHttpRequest object ကို နောက်ကွယ်ရှိ server တစ်ခုနှင့် data ဖလှယ်ရန်အတွက် အသုံးပြုနိုင်ပါသည်။ ဆိုလိုသည်မှာ စာမျက်နှာတစ်ခုလုံးကို ပြန်မတင်ဘဲ ဝဘ်စာမျက်နှာ၏ အစိတ်အပိုင်းများကို အပ်ဒိတ်လုပ်ရန် ဖြစ်နိုင်သည်။
XMLHttpRequest Object တစ်ခုကို ဖန်တီးပါ။
ခေတ်မီဘရောက်ဆာအားလုံး (Chrome၊ Firefox၊ Edge (နှင့် IE7+)၊ Safari၊ Opera) တွင် တပ်ဆင်ထားသော XMLHttpRequest object တစ်ခုရှိသည်။
XMLHttpRequest object တစ်ခုဖန်တီးရန်အတွက် Syntax-
variable = new XMLHttpRequest();
ဥပမာ
var xhttp = new XMLHttpRequest();
အထက်နမူနာတွင် အသုံးပြုထားသော "ajax_info.txt" ဖိုင်သည် ရိုးရှင်းသော စာသားဖိုင်ဖြစ်ပြီး ဤကဲ့သို့ တွေ့ရသည်-
<h1>AJAX</h1>
<p>AJAX is not a programming language.</p>
<p>AJAX is a
technique for accessing web servers from a web page.</p>
<p>AJAX stands for
Asynchronous JavaScript And XML.</p>
Domains များကို ဖြတ်ကျော်ဝင်ရောက်ပါ။
လုံခြုံရေးအရ၊ ခေတ်မီဘရောက်ဆာများသည် ဒိုမိန်းများတစ်လျှောက် ဝင်ရောက်ခွင့်မပြုပါ။
ဆိုလိုသည်မှာ ဝဘ်စာမျက်နှာနှင့် ၎င်းတင်ရန်ကြိုးစားသော XML ဖိုင်နှစ်ခုစလုံးသည် တူညီသောဆာဗာပေါ်တွင် တည်ရှိနေရမည်ဖြစ်သည်။
W3Schools ပေါ်ရှိ နမူနာများသည် W3Schools ဒိုမိန်းတွင်ရှိသော ဖွင့်ထားသော XML ဖိုင်များအားလုံး။
အထက်ဖော်ပြပါ ဥပမာကို သင့်ကိုယ်ပိုင် ဝဘ်စာမျက်နှာတစ်ခုတွင် အသုံးပြုလိုပါက၊ သင်တင်သည့် XML ဖိုင်များသည် သင့်ကိုယ်ပိုင်ဆာဗာပေါ်တွင် တည်ရှိနေရပါမည်။
XMLHttpRequest Object Methods
Method | Description |
---|---|
new XMLHttpRequest() | Creates a new XMLHttpRequest object |
abort() | Cancels the current request |
getAllResponseHeaders() | Returns header information |
getResponseHeader() | Returns specific header information |
open(method,url,async,user,psw) | Specifies the request method: the request type GET or POST url: the file location async: true (asynchronous) or false (synchronous) user: optional user name psw: optional password |
send() | Sends the request to the server Used for GET requests |
send(string) | Sends the request to the server. Used for POST requests |
setRequestHeader() | Adds a label/value pair to the header to be sent |
XMLHttpRequest Object Properties
Property | Description |
---|---|
onreadystatechange | Defines a function to be called when the readyState property changes |
readyState | Holds the status of the XMLHttpRequest. 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready |
responseText | Returns the response data as a string |
responseXML | Returns the response data as XML data |
status | Returns the status-number of a request 200: "OK" 403: "Forbidden" 404: "Not Found" For a complete list go to the Http Messages Reference |
statusText | Returns the status-text (e.g. "OK" or "Not Found") |