views:

37

answers:

2

I am a beginner at Jquery. What i want is to display the data using AJAX in a step by step manner. So let say if in my database there is a table "DATA" with a field name "info" having multiple rows as a data

info

1 2 3 4 5

Now i want to display all the five rows but after a certain delay of time let say after a second.

So i want to use Jquery with AJAX to retrieve data from mySQL table and display each row after a second.

Please provide an example for solving this problem. Thanks in Advance...

+1  A: 

You can use the delay() method. Let's suppose you have fetched records through ajax and use the fadeIn animation, you can go about something like this:

$('<div>').html(AjaxResponse).addClass('test').hide();
$('div.test').slideUp(300).delay(1000).fadeIn(400);

Or use setTimeout instead:

setTimeout(function() { $('div.test').slideUp(300).delay(1000).fadeIn(400); }, 5000);
Sarfraz
okie here is what i did..$.displayClicks = function(settings) { //To add overlay $('<div id="add-overlay"></div>').appendTo('body'); $('<div id="add-loading"></div>').appendTo('body'); for (i=1;i<=10;i++) { $.get('getdata.php',{ l:escape( document.location.pathname),id:i }, function(html) { $(html).appendTo('body'); $('#add-loading').remove(); } ); }}; now i only see the last data, not the ones in between - so i want to see it step by step. Please help!
Shahzaib
@Shahzaib: You should also post the code of of returning html in your question.
Sarfraz
A: 

jQuery DOES have a delay function, making this just a possible as you describe it.

You may have to delimit the data you send (with your PHP script) back to your jQuery script, so that in your jQuery you can split on that delimiter.

Then simply use a loop, combining the appearance functions and the delay()

Zane Edward Dockery
okie here is what i did..$.displayClicks = function(settings) { //To add overlay $('<div id="add-overlay"></div>').appendTo('body'); $('<div id="add-loading"></div>').appendTo('body'); for (i=1;i<=10;i++) { $.get('getdata.php',{ l:escape( document.location.pathname),id:i }, function(html) { $(html).appendTo('body'); $('#add-loading').remove(); } ); }}; now i only see the last data, not the ones in between - so i want to see it step by step. Please help!
Shahzaib