You are here: Re: Loading a PHP file/code via Javascript. « PHP Programming Language « IT news, forums, messages
Re: Loading a PHP file/code via Javascript.

Posted by d on 11/15/34 11:41

"Simon" <spambucket@example.com> wrote in message
news:46rh13Fc9380U1@individual.net...
>
>>
>> I've done something similar to this myself :)
>>
>> I found the best way to do it is to have your lengthy PHP script running
>> in a hidden iframe, occasionally spitting out chunks of javascript (in
>> complete <script> tags), and flushing the output after each tag is
>> written. The javascript can update a textual display, or a progress bar
>> or whatever, on the document holding the iframe. It's really simple to
>> use, and very effective.
>>
>> dave
>
> Hum, would you have a small example I could try?

----------------------------------------------------------------------
index.html:

<html>
<head><title>Example</title></head>
<body onload="document.getElementById('ifr').src='/script.php';">
<iframe id="ifr" style="display: none;" src=""></iframe>
<div id="output"></div>
</body>
</html>
----------------------------------------------------------------------

----------------------------------------------------------------------
script.php:

<html><head></head><body><?

function out($msg) {
echo '<script language="javascript"
type="text/javascript">parent.document.getElementById("output").innerHTML="'.$msg.'";</script>';
flush();
}

set_time_limit(0);

function long_ass_process($e) {
sleep(1);
}

$massive_array=array_pad(array(), 200, array());

foreach ($massive_array as $i=>$element) {
out('Processing #'.$i);
long_ass_process($element);
}

out('Done.');

?></body>
</html>
----------------------------------------------------------------------

(I've not tested it, btw)

> 'cause I am not sure I follow, if the php times-out after 30 seconds, (the
> default), then there is nothing it can do really.
> I need to divide the work in chunks of less that 30 seconds and somehow
> get the JavaScript to call each 'chunck' one at a time.

use set_time_limit(0) to disable the time-out.

> So I would need JavaScript to open a php script, wait for the output and
> handle the output.

Not if you disable the time-out :)

> Is it not possible to call another file on the server JavaScript and echo
> the output?

No need :)

> I hope my explanation is clear.
>
> Simon

I hope this helps!

dave

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация