In the Java Web Authentication system development, the customer requests to have the data update to be in the page pop-up prompt box, such convenient in the next staff can promptly know that has the new data submission, we can use the Ajax to realize these functions in addition to using the timely push technology.
The principle of code implementation, in the page to enable the timing of the implementation of AJAX requests, if the data is the most recent state, to perform voice prompts and pop-up box prompts, the disadvantage of this implementation is frequent call the database, the method is only suitable for the use of a small number of systems.
1, add voice prompts
<audio id= "sound" autoplay= "AutoPlay" >
Dynamically join the Playback speech file code:
document.getElementById ("Sound"). src= "<%=basepath%>admin/media/global.wav";
2, dynamic pop-up message prompt box:
Here I have imported jquery.gritter.js and jquery.gritter.css to implement the code:
JQuery (document). Ready (function () {setinterval (function () {$.post (' Ajax/linecheck ', function (data) {var json=eval ("
("+data+") "); $.each (Json,function (Index,item) {$ ("#line" +item.id). HTML ("") $.each (Item.locallist,function (index,item2) {if ( Item2.attendoclist!= "") {$ ("#line" +item.id). Append ("<li class= ' in ' id= '" "+item2.id+" ' ><div ' ") Avatar ' > "+item2.location+" </div><div class= ' message ' ><ul id=li "+item2.id+" ></ul></ Div></li> ")} $.each (Item2.attendoclist,function (INDEX,ITEM3) {if (item3.status==0) {$ (" #li "+item2.id). Append ("<li class= ' user ' ><span class= ' username ' >" +item3.person_name + "</span><br><span Style= ' color:red ' class= ' username ' > Time: "+ item3.today+" "+item3.times +" </span><br><span class= ' Username ' > Tel: "+item3.person_phone+" </span><br><span class= ' username ' > ID: "+item3.card_id+"
</span></li>
The above content is small series to introduce the JS real-time pop-up new message box and prompted the implementation of the Code, I hope to help you!