You are here: Re: Using AJAX, how can the page get state infomation from backgroud PHP script? « PHP Programming Language « IT news, forums, messages
Re: Using AJAX, how can the page get state infomation from backgroud PHP script?

Posted by amygdala on 04/18/07 03:37

"Marvin Zhang" <zyeming@gmail.com> schreef in bericht
news:1176865068.602740.33500@y5g2000hsa.googlegroups.com...
>> Just an idea, someone who's done it may know better.
>>
>> - Have your original PHP store it's "status" information in a Session
>> variable says $_SESSION["status_data"] which is updates as it runs
>>
>> - Have a timer on the Javascript side which creates a 2nd Ajax call
>> to a new getstatus.php, which then reads the status from the session and
>> sends back to the browser in this 2nd Ajax call.
>>
>> Not done much Ajax, I am assuming you can make another ajax call whilst
>> one is currently running??
>>
>> You might need to send the PHP session id back to the server when you
>> call getstatus.php, not sure.
>>
>> Let us no how you do :)
>
> I've tried out this approach. But unfortunately, there's a problem
> prevent this solution from working. If we send more than one request
> to the same session, all the requests will be queued. The second
> request will be send only after the response of the first request is
> received. So it's impossible to poll the information with second AJAX
> request.
>
> I'm planning to use a table in the database to record process
> information. The PHP script at the server side will update the record
> in the table and the web page sends request regularly to poll the
> information from database, just the same as you suggested. This will
> work cause we don't need to use session here. Using database, not only
> PHP script but also the daemon written in C++ can update that
> infomantion, this is what I need.
>
> Anyway, thanks for you original idea. That really helps very much :)
>

Hi Marvin,

I'm not sure if this will help but just some brainstorming here:

The XMLHttpRequest object for using AJAX stuff has a property 'readyState'
which can be:

0 // Uninitialized
1 // Loading
2 // Loaded
3 // Interactive
4 // Finished

If I were to hack something you have in mind I would look at Loading and
Interactive (not sure what the latter does)

My guess is that if you address one of these while the page is loading and
have PHP flush the buffer once in a while you could catch an XML node called
'loadedSoFar' or any output for that matter to poll the state of the page.

I recently saw a little AJAX script that didn't recieve XML at all but
simply some javascript statements where on the client javascript did an
eval( output ) on the recieved input. Pretty ingenius IMHO.

Anyway, hope this gives you some pointers.

Cheers.

 

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

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