Reply to Re: Ajax asynchronous is it possible ?

Your name:

Reply:


Posted by Erwin Moller on 08/23/07 09:08

Piotr Nowak wrote:
> Hi,
>
> Say i have a server process which listens for some changes in database.
> When a change occurs i want to refresh my page in browser by notyfinig it.
>
> I do not want to refresh my page i.e. every 5 seconds, i just want to
> refresh it ONLY on server change just like desktop applications do.
>
> The problem is that refreshing evry n seconds has to much impact on my
> web server. The refresh action should be taken only when something
> really happens that makes sense
>
> Is it possible ?
>
> greets, peter

Hi Peter,

This question is more javascript oriented than PHP.
Ajax could be a nice solution. But that only works when visitors have it
enabled of course. I hear different numbers, but around 10% of the
people have it disabled. In that case AJAX won't work of course.

In short:
1) Let the browser make a xmlhttprequest object.
Beware that different browsers need different approach.
Read up here: http://www.w3schools.com/ajax

2) Make a simple php script that your ajax code calls.
Let it return something like: REFRESH or NOREFRESH

3) In case of refresh: refresh. ;-)

Note: Make sure that the PHPscript that returns REFRESH or NOREFRESH is
a simple one. You don't want 10.000 browsers poll your server every 5
seconds...

But one thing: WHY do you want this behaviour? Doesn't everybody know
that a page that is untouched on the browserscreen for 20 hours may be
stale?

Regards,
Erwin Moller

[Back to original 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

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