52,782
社区成员
发帖
与我相关
我的任务
分享<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ajax实例</title>
<script language="javascript">
function showMsg() {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("msg").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "content.html", true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="button" onClick="showMsg()" value="调用ajax显示内容">
<span id="msg"></span>
</body>
</html>