0

I am using ajax to call a php script that is looping through a rather long data set. I would like to log the iteration ($i) to the console with each pass.

Is there a jQuery method that can "listen" while the script is running and log each pass to the console?

Sorry for not posting an example... I'm a little pressed for time.

durron597
  • 30,764
  • 16
  • 92
  • 150
Wes Dollar
  • 377
  • 5
  • 15
  • Is `$i` a JS variable or PHP variable? – Rory McCrossan Nov 01 '13 at 20:22
  • PHP only sends data once it has completed the script and sends a `200` status unless you mess around with Output Buffering as suggested here http://stackoverflow.com/questions/6048282/php-display-status-of-loop but I am not sure how AJAX is going to handle it. – MonkeyZeus Nov 01 '13 at 20:31

1 Answers1

1

Since the php script wont return stuff through the server (and therefore through ajax) until it is done executing or you flush the output buffer (which would mean you couldn't send anything else later), you need to log its iterations somewhere, a file, session (this is tricky since they can't access it concurrently), the database or something like Memcache and then read that from a second script you would poll with ajax.

Polling isn't exactly listening like you mentioned in your question though. If polling isn't good enough you will need to look into setting up something like COMET, but its likely with a short enough polling interval, for this purpose, it would be acceptable.

Community
  • 1
  • 1
MWJump
  • 91
  • 5