AJax学习笔记

//Aja请求局部刷新示例
function GetName() {
var XmlHttp;
if (window.XMLHttpRequest) { //主流浏览器都有
XmlHttp = new XMLHttpRequest();
}
else {//兼容IE5、IE6
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
XmlHttp.onreadystatechange = function () { //监听服务器数据返回状态
if (XmlHttp.readyState == 4 && XmlHttp.status == 200) {
document.getElementById("name").value = XmlHttp.responseText;
}
};
//get方式适合请求少量数据 postt方式适合请求大量数据
//GetName为后台方法
//true:异步请求 fasle:同步请求
XmlHttp.open("get", "GetName", true);
XmlHttp.send();//发送请求
}

原文地址:https://www.cnblogs.com/zxwDont/p/9575396.html