Ajax笔记(一)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ajax.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">

var xmlHttpRequest=null;

function ajaxSubmit(){
if(window.ActiveXObject){
xmlHttpRequest
=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttpRequest
=new XMLHttpRequest();
}
if(null!=xmlHttpRequest){
xmlHttpRequest.open(
"GET","AjaxServlet",true);
xmlHttpRequest.onreadystatechange
=ajaxCallBack;
xmlHttpRequest.send(
null);//GET的时候设为空,或者不写

}

function ajaxCallBack(){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
var responseText=xmlHttpRequest.responseText;
document.getElementById(
"div1").innerHTML=responseText;
}
}
}
}



</script>
</head>

<body>
<input type="button" value="get content from server" onclick="ajaxSubmit();"/>
<div id="div1"></div>
</body>
</html>

 

posted @ 2012-02-21 14:20  一直在等  阅读(285)  评论(0编辑  收藏  举报