//1创建对象 XMLHttpRequest
var request = createXHR();
function createXHR() {//判断浏览器兼容 var xhr;
if (XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
return xhr;
}
function send() {
document.getElementById("d").innerHTML = "加载中...";
//2初始化
request.open("get", "02_getTime.ashx?_=" + Math.random(), true);
//3注册事件
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200) {
var res = request.responseText;
document.getElementById("d").innerHTML = res;
} else {
document.getElementById("d").innerHTML = "服务器内部错误";
}
}
}
//4.发送请求
request.send();
}