------ Solution ---------------------------------------- ----
general idea is that, you try to write something, I did not write drafts run .
<script type="text/javascript">
function run(){
window.setInterval(ajaxAccess(),6000);
}
/*创建XMLHttpRequest的对象*/
var xmlhttp;
function ajaxAccess(){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
/*执行回调函数*/
var responseValue;
xmlhttp.onreadystatechange = function(){
if(xmlhttp.status==200&&xmlhttp.readyState==4){
responseValue = xmlhttp.responseText();
if(responseValue!=null){
/*有内容变化时,给页面一个反馈*/
document.getElementById("testDiv").innerHTML = responseValue;
}
}
}
/*提交到一个action上去,action去访问数据库,加个判断,有内容就返回*/
var url = "";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
</script>
<body onload="run()">
<div id="testDiv">数据库发生变化的话,把内容显示到这里</div>
</body>
------ For reference only ----------------------------------- ----
question is not very clear . . .
------ For reference only -------------------------------------- -
you mean to add data to the database page automatically prompt function it ?
If this is the case , ajax can be achieved.
------ For reference only -------------------------------------- -
ask how to achieve ? A source do ?
------ For reference only -------------------------------------- -
question is : If the data in the database changes, such as add, delete , modify, then the page will show what has changed , rather than the client sent the request. Internet received the ajax is to establish a long cable to connect to achieve, but I do not know specifically how to achieve ?
------ For reference only -------------------------------------- -
ajax but the realization of the long connection , but I do not know how to write specific code .... ask !
------ For reference only -------------------------------------- -
the more difficult , two questions:
1, database data changes, how to notify the application system ; most database is no such function , basically rely on the procedures to regularly poll ; currently known , can take the initiative to notify the application by the database system data changes is Oracle;
2, application data changes after the system knows how to push data to the browser ; This is based on either a long connection ( not necessarily Ajax, but it consumes server resources , a connection , it takes a long thread ) ; either is the browser -side timer request .
Can you understand the above two questions? Can , then you can continue to explore .
------ For reference only -------------------------------------- -
write a timer on the page is not finished it :
function run () {
window.setInterval (ajaxfunction (), 60000);
}
function ajaxfunction () {
/ * here to visit the servlet or action method of interacting with the Dao * /
}
page loads
------ For reference only --------------- ------------------------
Why do consume server resources , the inside pages regularly , it is consumed resources the client browser bar, that is timed words will often send a request , this is a flaw.
------ For reference only -------------------------------------- -
question is not very clear
------ For reference only ----------------------------- ----------
few months following this comment :
/ * When the body load when performed regularly ajaxAccess () function , 6000 refers to 6 seconds * /
function run () {
window.setInterval (ajaxAccess (), 6000);
}
------ For reference only ---------------------------------- -----
landlord and you did not see what I mean .
landlord requirements: "instead of a client send request"
My argument is : "Based on a long connection "
why " consume server resources," because " a long connection is necessary to consume a thread ."
------ For reference only -------------------------------------- -
through spring AOP implementation monitoring of the DAO layer , and then push back the DWR achieve your function .
------ For reference only ----------- ----------------------------
go with you and I think , but this can only listen to the program changes to the database , if it is to directly modify the database , there is no way to achieve it.
------ For reference only -------------------------------------- -
it can only be timed client sends a request , and now can be used, the more practical
------ For reference only ------------ ---------------------------
main floor is good intelligence.
If the direct operation of the database , then view the database operation logs it, manipulating data extracted from showing on the page. But also very troublesome.
------ For reference only -------------------------------------- -
what the problem down . . Still do not understand . .
------ For reference only -------------------------------------- -
lies database has no such feature , such as flip-flops , once changed to call java method returns the changed data
------ For reference only --------- ------------------------------
6th floor , as I have said : Oracle is there, called "Database Change Notification", the other mostly not , see:
http://www.builder.com.cn/2007/1022/571942.shtml
------ For reference only --------------- ------------------------
LZ achieve it ? can share the source code ... 546454088@qq.com
没有评论:
发表评论