读书人

急求!关于jsp页面ajax实时读取数据

发布时间: 2013-08-13 16:43:28 作者: rapoo

急求!!关于jsp页面,ajax实时读取数据库,显示数据的代码!!
运用stuts,在JSP页面显示从数据中读取的数据,数据库在变,想要无刷新的实时显示数据。
网上搜了些AJAX的代码,都不太明白,哪位高手给发个代码,最好有注释!!谢谢了!分不是问题!!
也可发送到邮箱onion11@126.com 跪谢!!
[解决办法]
思路就是 setTimeout/setInterval +ajax轮询服务器获取数据
[解决办法]
看样子你得好好去把ajax基础知识先学学。这个不难!
[解决办法]

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
var xhr;
var num;
function CreateXmlHttp() {
if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
xhr = new XMLHttpRequest();
}
}
function SendReq() {
num = document.getElementById("txtNum").value;
CreateXmlHttp();
var url = "Handler.ashx?num=" + num;//这儿应该是你请求的那个JSP页面
xhr.open("GET", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {


var result = xhr.responseText;
//解析服务器返回的数据
}
}
xhr.send(null);
}
function ProcessRequest() {
var requestId = setInterval("SendReq()",2000);
}
</script>
</head>
<body>
<input type="button" value="获得数据" onclick="ProcessRequest()"/>
</body>
</html>


[解决办法]
引用:
HTML code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
var xhr;
var num;
function Cre……


服务器端的数据如何传回来的?
比如我post到一个servlet,这个servlet如何传回数据呢?
[解决办法]
我上传了一个例子,楼主可以看看
http://download.csdn.net/source/3196672
[解决办法]
引用:
HTML code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
var xhr;
var num;
function Cre……

你好,请问在JS文件中使用这种方式编码后name和value值,在发送之后,如何在JSP文件中对value的中文字符解码呢?
xmlHttp.send("name=" + encodeURIComponent(_code.id) +
"&value=" + encodeURIComponent(_code.value));//发送包含用户输入信息的请求

读书人网 >Ajax

热点推荐