Solved

How to build in jquery auto data refresher with animation?

Posted on 2009-07-08
1
560 Views
Last Modified: 2012-05-07
OK, what I need is - I've got a text:

          280 049 members

Where I want to: every 5 seconds, jquery make a ajax call to link which would return actual number of rows. Then, I want to animate those 1 - 2 last digits ('refresh', blink or sth)

Any ideas?
0
Comment
Question by:AndyPSV
1 Comment
 
LVL 16

Accepted Solution

by:
anoyes earned 500 total points
ID: 24975032
Basically you need to use setInterval to make an ajax call over and over, and when that AJAX call completes it will update the numbers and draw attention to them if they've changed.  Something like this should do the trick.

/path/to/file.php is just your server-side script that returns the number, and it should return only the number.

Add <span id="update"></span> around the numbers you want updated.

Grab the jQuery UI library (customize it if you don't need the whole thing) from here: http://jqueryui.com/download so that we can use the effects from it to draw attention to the updated numbers.

<script type="text/javascript">
$(function() {
  setInterval(function() {
    $.get('/path/to/file.php', function(response) {
      var orig = $('span#update').html();
      if (orig != response) {
        $('span#update').html(response);
        $('span#update').effect('pulsate', {}, 500);
      }
    });
  }, 5000);
});
</script>

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Placeholder text not disappearing in Contact Form 7 2 17
jquery auto complete 11 17
how can i check if the text is an Isogram ? 2 27
Jquery 10 20
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question