0

I make different queries with PHP and jQuery and I get the results with .ajax(),when all queries return their values.

What I want to do is to get those values as soon as they are ready. Now user has to wait until all the queries are done, but the first query returns its value 30 seconds before the second one, so I don't want the user to wait to see all results at once, I want them to see the result just the result returns.

How can I do this?

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
kent ilyuk
  • 119
  • 1
  • 4
  • 9
  • The results should be available soon as .ajax() is done running. Can you show some code? Sounds like your timeout between .ajax() calls just needs to be shorter but I can't tell. – Jonathan Kuhn Jul 27 '10 at 16:03
  • 1
    $.ajax({ type: "POST", url: "query.php", data: values, success: function(msg){ $('.result').html(msg); } }); using this way, i get all returning values once the php file finished working. what i want is to get those values when they are created. – kent ilyuk Jul 27 '10 at 16:30

1 Answers1

1

If you are waiting for multiple database queries to return, you may consider breaking up your web services into multiple AJAX calls. In other words, make 2 AJAX requests, one for the first query and another for the second query (which gets its value 30 seconds after the first). That way you can return the first query back to the page and display it - or whatever needs to be done - while waiting for any additional AJAX calls.

Of course you can extend this technique to additional AJAX requests as needed.

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284