使用原始的ajax异步程序出现的的错误
初学ajax时间不长,现在用xmlhttprequest对象遇到个问题。在判断request.readyState==4 && request.states==200的时候出现错。先把代码贴出来大家看看哪里有错误。
<script type="text/javascript">
var request = createXMR();
function createXMR() {
var xmr;
if (window.XMLHttpRequest) {
xmr = new XMLHttpRequest();
}
else {
xmr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmr;
}
function send() {
document.getElementById("d1").innerHTML = "数据加载中...";
request.open("get", "01.ashx", true);
request.onreadystatechange = function () {
if (request.readyState == 4 && request.states == 200) {
var data = request.responseText;
document.getElementById("d1").innerHTML = data;
}
else {
document.getElementById("d1").innerHTML = "服务器内部错误";
}
}
request.send();
}
</script>
<input type="button" value="get" onclick="send()" />
<div id="d1">
</div>