Posted on 2012-02-24 23:30
哈希 阅读(181)
评论(0) 编辑 收藏 所属分类:
Js and Jquery 常用总结
http://www.wujianrong.com/archives/2007/05/20jspajax.html 简单用例
http://www.ibm.com/developerworks/cn/web/wa-ajaxintro/ IBM—Ajax讲解
http://www.w3schools.com/ajax/ajax_example.asp Ajax—Example W3CSchol
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
">
<html>
<head>
<script src="ajax.
js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page using AJAX</title>
</head>
<body>
<a onclick="sendRequest('GET','index.jsp')" href="#">Server Date Time:</a>
<div id="ajax_res">Server Date Time will replace this text.</div>
</body>
</html>
index.jsp
<html>
<body>
<%=new java.util.Date()%>
</body>
</html>
ajax.
jsfunction createRequestObject(){
var req;
if(window.XMLHttpRequest){
//For Firefox, Safari, Opera
req = new XMLHttpRequest();
}
else if(window.ActiveXObject){
//For IE 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
//Error for an old browser
alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
}
return req;
}
//Make the XMLHttpRequest Object
var http = createRequestObject();
function sendRequest(method, url){
if(method == 'get' || method == 'GET'){
http.open(method,url);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
function handleResponse(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response){
document.getElementById("ajax_res").innerHTML = response;
}
}
}
run this application may be u get some clue