How can i display a page while still loading with load()?

How can i display a page while still loading with load()?

Hello,
ive got a slight problem. I'm trying to load a php file with load() to write entries to a mysql database. I want to keep track of the progress and update a progress bar while the entries are being written.
The problem is that all the javascript code inside the php file im loading wont be executed until the file is completely loaded (after all the entries have been written to the db).
Is there a way to change the load() function to display the content while its loading and not wait until its finished?
I hope you can help me out :)
Thanks in advance
Rob


EDIT:
here is a code example to make it easier to understand:
  1. <div id="progressbar"></div>
  2. $('#progressbar').progressbar({value: 0});
  3. $('#divAjax').load('addtomysql.php');

addtomysql.php:
  1. for ($i=1;$i<=5;$i++) {
  2. mysql_query("INSERT INTO test (something) VALUES ('bla')");
  3. $percentage = $i / 5 * 100;
  4. echo '<script type="text/javascript">
  5. $('#progressbar').progressbar('option', 'value', " . $percentage . ");
  6. </script>';
  7. }

since the addtomysql.php file is loaded once its completed it just updates the progressbar to 100%..