ajax call while updating page

I have an ajax call to one php script via jquery but it takes a lot of time to return results , So I would like to know how can I display results as its are being printed on my script. here just example of my php script:

// process.php
for($i = 0; $i <= 4; $i++){
echo json_encode(array("name" => $i) );
sleep(2); // this sleeps for 2 seconds

Now with my jquery i am calling that page and have a form with id ajaxquery on page:

$("#ajaxquery").live( "submit" , function(){
    var formdata = $(this).serialize(); 
            type: "POST",
            url: "process.php",
            data: formdata,
            dataType: "json",
            success: function(data)

    return false; 

now this will output all results at same time after few seconds in div#success but how can i achieve it print that echo statements as soon process.php process it and then again wait 2 seconds and add next result in div success. thanks for any help.


You will have to setup a javascript timer on the client and call you php script every two seconds to get the new data. That data you can append for example with the jquery .append function.

Need Your Help

Mongoid 1-N insert duplicate key error

ruby-on-rails mongodb ruby-on-rails-4 mongoid mongoid4

I'm getting a weird behaviour from Mongoid 4.0.0 and Rails 4, I have a 1-N relationship and I get a duplicate key error index when I try to save the N side of the relationship. Let me show you some...

How to get only date part while using dateadd() and getdate()

sql sql-server tsql date

I want to display records of last 4 months from current date.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.