原始ajax例子
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>原始ajax例子</title>
</head>
<body>
<button id="btnajax">ajax调用</button>
<br/>
<div id="divResult"></div>
<script type="text/javascript">
//跨浏览器获取xmlhttpRequest对象
function AjaxXhttpRequest(){
var xmlHttp;
try{
xmlHttp = new XMLHttpRequest();
}
catch(e){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmlHttp = new ActiveXObject("Microsoft.MXLHTTP");
}
catch(e){
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
return xmlHttp;
}
//使用XMLHttpRequest对象发送请求
var xhr = newAjaxXmlHttpRequest();
document.getElementById("btnajax").onclick = function(){
var xhr = new AjaxXmlHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
document.getElementById("divResult").innerHTML = xhr.responseTest;
}
}
xhr.open("GET","../data/AjaxGetCityInfo.aspx?resultType = html",true);
xhr.send(null);
}
</script>
</body>
</html>