Solved

How to build in jquery auto data refresher with animation?

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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)

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now