0

i need to do some stuff on PHP (tha will take a lot of time...), and as it flows, i need to send a number (maybe the percentage), to the page with the ajax call, update a loading bar.

But i have no idea, of how to "load" a page string that is'n yet loaded...

And also, is there a "word" for this?

Ivan Seidel
  • 2,394
  • 5
  • 32
  • 49

1 Answers1

0

The server could send back JSON or XML that contains two fields; percent and payload. If the percent is less than 100, your ajax client then performs the same ajax call again (you'll need some kind of request ID tracking in the request). When it is 100 you can pull the data out of the payload. The PHP of course would either return a percent less than 100 and no payload, or 100 and the full data when it's ready.

Your client ajax should be throttled to poll once every few seconds, but it sounds like that should accomplish what you want.

Edit: Incidentally, the PHP response could contain data such as how long to wait before asking again, expected time to complete, etc, as needed.

mrusinak
  • 1,002
  • 1
  • 12
  • 22
  • I thought in doing this way, but maybe there is something with only one request... do you know any thing about this? Thanks – Ivan Seidel Aug 22 '12 at 04:22
  • Not really - http://stackoverflow.com/questions/2474528/showing-progressbar-progress-with-ajax-request has a couple other suggestions, but showing progress even in native applications can be tricky business. – mrusinak Aug 22 '12 at 13:22
  • http://stackoverflow.com/questions/4993502/jquery-load-progress-bar might also have some ideas for you – mrusinak Aug 22 '12 at 13:25