Simple code to implement jquery timer

  • 2020-03-29 23:49:10
  • OfStack

Simple code to implement jquery timer.

Today, the project encountered a message module at the top of the navigation bar. I want to realize that when the message is received, it can be refreshed in time to display the number of received messages.

1. Ajax tags using struts2.

2. The use of jquery.

Struts2 is a bit of a pain, but jquery is a bit easier to use.
 
$(function(){ 
run(); 
var interval; 
function run(){ 
interval = setInterval(chat,"3000"); 
} 
function chat(){ 
$.post("searchMessage.action",{"mark":"receive","ajax":"ajax"},function(data){ 
$("span[name='mes']").html(data.num); 
},"json"); 
} 
$("#closeChat").click(function(){ 
clearTimeout(interval); 
}); 

}); 

Related articles: