Solved

How to build in jquery auto data refresher with animation?

Posted on 2009-07-08
1
562 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
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…

726 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