• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 788
  • Last Modified:

Update page using Ajax while PHP script is running

I am using PHP to parse XML data, which ultimately gets stored into a database. However, while I am downloading and parsing the XML (which takes about 30 seconds), I would like to give the user status reports.

Since I am on Apache 1.0.33, I cannot do any type of page flushing to force output to the browser.

What I would like is to use Ajax to update the status div element while my script is running.

The only solution I have in mind is to use 2 hidden iframes. 1 frame holds the actual script that parses data, and stores messages in a $_SESSION and a second script that reloads (using javascript) every second or so, reads the contents of the $_SESSION message and updates the form.

However, this does not seem to be a very elegant solution. I guess I want more of a event-driven solution.
1 Solution
You could just take your own solution of using iframes and two scripts and do it with AJAX instead of the iframes.

Call the script that parses the XML through xmlhttprequest, then call another script with xmlhttprequest to constantly output the value of a certain session variable, using the output of the second script to fill a div.

Update the value of the session variable as often as you can within the xml parsing script to give your users more of an idea of whats going on.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now