Solved

How to build in jquery auto data refresher with animation?

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

828 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