如何使用一個XMLHttpRequest對象
In?Mozilla,?Firefox,?Safari,?and?Netscape,?you?create?an?instance?of?the?XMLHttpRequest?object
by?doing?the?following:
<script>var?xhr?=?new?XMLHttpRequest();</script>
For?Internet?Explorer:
<script>?var?xhr?=?new?ActiveXObject("Microsoft.XMLHTTP");</script>
Here?is?an?example?of?using?the?XMLHttpRequest?object:
<script>
var?xhr?=?null;
if?(window.XMLHttpRequest){
xhr?=?new?XMLHttpRequest();
}?else?{
xhr?=?new?ActiveXObject("Microsoft.XMLHTTP");
}
if?(xhr)?{
var?url?=?"/someURI";
xhr.onreadystatechange?=?xhrCallback;
xhr.open("get",?url,?true)
xhr.send()
}
function?xhrCallback()?{
if?(xhr.readyState?==?4)?{
if?(xhr.status?==?200)?{
alert("Ok");
}?else?{
alert("Problem?retrieving?Ajax?response");
}
}
}
</script>
posted on 2007-03-02 11:23
Ken.Lee 閱讀(168)
評論(0) 編輯 收藏 所屬分類:
Ajax