XMLHttpRequest အားကိုယ်စားလှယ်မှု
- XML DOM အမှုထမ်း: XMLHttpRequest အားကစား အရင်
- နောက်ပိုင်း DOM စာရင်း တံဆိပ်
XMLHttpRequest အမှုသိမ်း က ဝတ်ထမ်းပြီး အက်ယ်ဟီယံ နှင့် ကွန်ပျူတာ ကို ဆက်သွယ်ရန် နည်းလမ်းများ ကို ပေးသည်。
XMLHttpRequest အမှုသိမ်း ဆိုသည် မဟုတ်မှာ
XMLHttpRequest အမှုသိမ်းသည်Developer's dreamကြောင်းကြောင်းကြားပါတယ်။
- Page အသုံးပြုချိန်တွင် အခြေအနေ မပြောင်းလဲသော စီမံကိန်း အသုံးပြုပါ။
- စိတ်သမတ် ပြီးသွားပြီးနောက် အင်တာနက် အစိုးရ မှ အချက်အလက် တောင်းဆိုပါ။
- စိတ်သမတ် ပြီးသွားပြီးနောက် အင်တာနက် အစိုးရ မှ အချက်အလက် သို့မဟုတ်
- ဗဟိုကာအချုပ် မှ အင်တာနက် အစိုးရ သို့ အချက်အလက် ပေးပို့ပါ။
အင်တာနက် အစိုးရ အားလုံး သည် XMLHttpRequest အကိုင်း ကို ထောက်ပံ့ပါသည်။
အကျိုးသတ္တု:Text အသုံးပြုချိန်တွင် ပေါ်ပေါ်ရှိ အင်တာနက် အစိုးရ မှ အသုံးပြုသမဂ္ဂ ဖြင့် ဆက်သွယ်ပါ။.
XMLHttpRequest အကိုင်း ဖွဲ့စည်းရန်
အသုံးပြုသော ကန်ထောက်ခံသမဂ္ဂ အသုံးပြုရန် အသုံးပြုသော အကန်ခွဲအသုံးပြုသမဂ္ဂ ဖြင့် အသုံးပြုပါ။
အင်တာနက် အစိုးရထိုင်း အသစ် အားလုံး တွင် (IE ၇ ပါ):
xmlhttp=new XMLHttpRequest()
အင်တာနက် အစိုးရထိုင်း ၅ နှင့် ၆ တွင်:
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
အကျိုးသတ္တု
<script type="text/javascript"> var xmlhttp; function loadXMLDoc(url) { xmlhttp=null; if (window.XMLHttpRequest) {// code for all new browsers} xmlhttp=new XMLHttpRequest(); alert("Your browser does not support XMLHTTP."); else if (window.ActiveXObject) {// code for IE5 and IE6} xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); alert("Your browser does not support XMLHTTP."); if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change; xmlhttp.open("GET",url,true); xmlhttp.send(null); alert("Your browser does not support XMLHTTP."); else { alert("Your browser does not support XMLHTTP."); alert("Your browser does not support XMLHTTP."); alert("Your browser does not support XMLHTTP."); function state_Change() { if (xmlhttp.readyState==4) {// 4 = "loaded"} if (xmlhttp.status==200) {// 200 = OK} // ...our code here... alert("Your browser does not support XMLHTTP."); else { alert("Problem retrieving XML data"); alert("Your browser does not support XMLHTTP."); alert("Your browser does not support XMLHTTP."); alert("Your browser does not support XMLHTTP."); }
response.write အခြေခံ အကိုင်းအခြား ကို အသုံးပြု၍ အပြီးအပြတ် ကို အကောင်းစား ပြန်လည်ပေးပေးသည်。
အစီရင်ခံပုံ:onreadystatechange သည် အခုပြောင်း အကိုင့်ဖြစ်ပါသည်။ အကျယ်း (state_Change) သည် ဖိုင်ခွဲမှာ အသုံးပြုရသော အကိုင့် ဖြစ်ပါသည်။ XMLHttpRequest အကိုင်း အခြေအနေ အသစ် (uninitialized) မှ ၄ (complete) အထိ ပြောင်းလဲသည်။ အခြေအနေ ၄ အခါတွင်သာ ကုလသမဂ္ဂ အသုံးပြုပါ။
为什么使用 Async=true ?
我们的实例在 open() 的第三个参数中使用了 "true"。
该参数规定请求是否异步处理。
True 表示脚本会在 send() 方法之后继续执行,而不等待来自服务器的响应。
onreadystatechange 事件使代码复杂化了。但是这是在没有得到服务器响应的情况下,防止代码停止的最安全的方法。
通过把该参数设置为 "false",可以省去额外的 onreadystatechange 代码。如果在请求失败时是否执行其余的代码无关紧要,那么可以使用这个参数。
response.write အခြေခံ အကိုင်းအခြား ကို အသုံးပြု၍ အပြီးအပြတ် ကို အကောင်းစား ပြန်လည်ပေးပေးသည်。
XML / ASP
您也可以把 XML 文档打开并发送到服务器上的 ASP 页面,分析此请求,然后传回结果。
<html> <body> <script type="text/javascript"> xmlHttp=null; if (window.XMLHttpRequest) //{ code for IE7, Firefox, Opera, etc. xmlHttp=new XMLHttpRequest(); alert("Your browser does not support XMLHTTP."); else if (window.ActiveXObject) //{ code for IE6, IE5 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); alert("Your browser does not support XMLHTTP."); if (xmlHttp!=null) { xmlHttp.open("GET", "note.xml", false); xmlHttp.send(null); xmlDoc=xmlHttp.responseText; xmlHttp.open("POST", "demo_dom_http.asp", false); xmlHttp.send(xmlHttp.responseText); document.write(xmlHttp.responseText); alert("Your browser does not support XMLHTTP."); else { alert("Your browser does not support XMLHTTP."); alert("Your browser does not support XMLHTTP."); } </script> </body>
</html>
ASP စာရင်းကို ဗဟိုသားစာပုံဖော် ဖြင့် ရေးသားပါ <% set xmldoc = Server.CreateObject("Microsoft.XMLDOM") xmldoc.async=false xmldoc.load(request) for each x in xmldoc.documentElement.childNodes if x.NodeName = "to" then name=x.text next response.write(name)
%>
response.write အခြေခံ အကိုင်းအခြား ကို အသုံးပြု၍ အပြီးအပြတ် ကို အကောင်းစား ပြန်လည်ပေးပေးသည်。
TIY
XMLHttpRequest အားကစား သည် W3C အခြေခံ အုပ်ချုပ်ကိန်း ဖြစ်ပါသလဲ?
အခြား W3C အကြောင်းကြား အခြေခံ အုပ်ချုပ်ကိန်း သည် XMLHttpRequest အားကစား ကို အသိအမှတ်ပြု ခြင်း မရှိပါ။
သို့သော်လည်း၊ W3C DOM Level 3 ၏ "Load and Save" အခြေခံ အုပ်ချုပ်ကိန်း သည် အတူတူ အကျိုးဆက်ရှိ အကျိုးဆက်များ ပါဝင်သည်၊ သို့သော် အခြား ဘာသာပြန် ကို သုံးစွဲ ခြင်း မရှိပါ။
- XML DOM အမှုထမ်း: XMLHttpRequest အားကစား အရင်
- နောက်ပိုင်း DOM စာရင်း တံဆိပ်