Ajax是浏览器端的异步刷新。只是局部更新。使得网络慢的时候用户不会等太久。
步骤(例子):
<title>首页</title>
</head>
<script type="text/javascript">
function dizhi(){
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("GET","ajax1.jsp","true");
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
div1.innerHTML = xmlHttp.responseText;
}
}
alert(xmlHttp.readyState);
xmlHttp.send();
}
</script>
<body>
欢迎来到重庆文理学院
<input type="button" value="学校地址" οnclick="dizhi()">
<div id="div1"></div>
步骤:
1:var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
//IE浏览器实例化 "Msxml2.XMLHTTP"对象
2:xmlHttp.open("GET","ajax1.jsp","true");
//异步提交的目标和方法
3:xmlHttp.onreadystatechange() = function(){
//xmlHttp状态改变时,进行处理代码
4: if(xmlHttp.readyState==4){
//xmlHttp.readyState 有0~4 5种状态
0:未初始化状态,未调用open()
1:已经初始化状态,已经调用open()
2:发送数据状态,调用send()以后
3:数据传送中状态,已经接受部分,但是没有接受完成
4:完成状态,数据接受完成
div1.innerHTML = xmlHttp.responseText;
//xmlHttp.responseText 是从目标提取出来的文本内容
}
5:xmlHttp.send();
}