Ajax使用步骤
JavaScript编写AJax代码
- 创建XMLHttpRequest对象,用于和服务器交换数据
- 向服务器发送请求
- 获取服务器响应数据
var xmlhttp;
if (window.XMLHttpRequest) {
// IE7+, FireFox, Chrome
xmlhttp = new XMLHttpRequest();
} else {
// IE5,IE6
xmlhttp = new ActiveXObject("Mirosoft.XMLHTTP");
}
//向服务器发送请求
xmlhttp.open("GET", "URL");
xmlhttp.send();
//获取服务器响应数据
xmlhttp.onreadystatechange() = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//处理xmlhttp.responseText
alert(this.responseText);
}
}

浙公网安备 33010602011771号