Simple code to implement jquery Timer

Source: Internet
Author: User

Simple code to implement jquery timer.

Today, the project encountered a message module at the top of the navigation bar. to achieve this, You can promptly refresh the received message and display the number of received messages. I thought for a long time. I thought of two methods,

1. Use the Ajax tag of struts2.

2. Use jquery.

Struts2 is a little troublesome. jquery is relatively simple to use jquery. The following code is attached: get data from the server every 3 seconds. Then assign the value to the dom object to be displayed.
Copy codeThe Code is as follows:
$ (Function (){
Run ();
Var interval;
Function run (){
Interval = setInterval (chat, "3000 ");
}
Function chat (){
$. Post ("searchMessage. action", {"mark": "receive", "ajax": "ajax"}, function (data ){
$ ("Span [name = 'mes ']" pai.html (data. num );
}, "Json ");
}
$ ("# CloseChat"). click (function (){
ClearTimeout (interval );
});

});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.