<!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>