如何使用一个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 阅读(165)
评论(0) 编辑 收藏 所属分类:
Ajax