console
var xmlhttp = null;
function createXMLHttpRequest() { //验证能否使用IE浏览器
if (window.ActiveXObject) { // IE浏览器
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) { // 非IE浏览器
xmlhttp = new XMLHttpRequest();
}
}
function startRequest() {
createXMLHttpRequest(); //创建一个XMLHttp对象
var url = "index.php"; // 要使用的服务器URL
xmlhttp.open("get", url, true); // 使用open()方法发送一个异步请求
xmlhttp.onreadystatechange = function() { //存储函数(或函数名),每当 readyState 属性改变时,就会调用该函数。
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { //当 readyState 等于 4 且状态为 200 时,表示响应已就绪:
alert(xmlhttp.responseText);
}
}
xmlhttp.send(null);
}
<button name="button" onclick="startRequest();"/>获取服务端文本</button>