By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,363 Members | 2,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,363 IT Pros & Developers. It's quick & easy.

Ajax Asynchronous refresh. Is it possible ?

P: n/a
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
Aug 23 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
I dont think that is possible, you cant "notify" a web browser client that
something has changed on the server. That is the nature of web sites and web
applications, they are "stateless".

"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
Aug 23 '07 #2

P: n/a
NH pisze:
I dont think that is possible, you cant "notify" a web browser client that
something has changed on the server. That is the nature of web sites and web
applications, they are "stateless".

"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
stateless means that theres no information about previous request in the
new one, its forgotten.
i just want to get one simple response right from the server when
something happens to update my client browser view.
Aug 23 '07 #3

P: n/a
As long as there is some asp.net code you can run that will return a true or
false as to the server being updated then this is possible. Use an ajax
call every x seconds and when it returns true issue a page reload via
javascript.

"Piotr Nowak" <p.******@STRIPTHISwasko.plwrote in message
news:fa**********@atlantis.news.tpi.pl...
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

Aug 23 '07 #4

P: n/a
Aidy pisze:
As long as there is some asp.net code you can run that will return a true or
false as to the server being updated then this is possible. Use an ajax
call every x seconds and when it returns true issue a page reload via
javascript.

"Piotr Nowak" <p.******@STRIPTHISwasko.plwrote in message
news:fa**********@atlantis.news.tpi.pl...
>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

yes, but the page reload is not as much impact as server side actions
because every x second i would have to do a database hit to check if
something changed, then do a page refresh.
im not shure if i was enough clear..
Aug 23 '07 #5

P: n/a
yes, but the page reload is not as much impact as server side actions
because every x second i would have to do a database hit to check if
something changed, then do a page refresh.
im not shure if i was enough clear..
It's hard to advise on solutions without knowing more about how it can be
determined when a refresh is needed. You 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."

Could your process do something like create/update a file saying to refresh,
your ajax call will see if the data in the file indicates a refresh is
needed. If it is then the call will return that and update the file to set
it back to no refresh being needed. That way every x seconds you are merely
accessing the file system and not the database.
Aug 23 '07 #6

P: n/a
No the server can't reach a web client. This is always the client that sends
a request to the server and the server only responds to incoming requests.

You could issue an AJAX call to the server that just tell if the client
should be updated. If not you have nothing more to do, if yes you can issue
your more complex ajax calls that would update parts of your pages...

Youn may want to explain a bit more what you are trying to do...
--
Patrice

"Piotr Nowak" <p.******@STRIPTHISwasko.pla écrit dans le message de news:
fa**********@atlantis.news.tpi.pl...
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

Aug 23 '07 #7

P: n/a
Patrice pisze:
No the server can't reach a web client. This is always the client that sends
a request to the server and the server only responds to incoming requests.

You could issue an AJAX call to the server that just tell if the client
should be updated. If not you have nothing more to do, if yes you can issue
your more complex ajax calls that would update parts of your pages...

Youn may want to explain a bit more what you are trying to do...
--
Patrice

"Piotr Nowak" <p.******@STRIPTHISwasko.pla écrit dans le message de news:
fa**********@atlantis.news.tpi.pl...
>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

Sure its quite generic problem.

Imagine you develop a online game, like ogame.
There's a lot action behind the scenes, players are making some actions
that take some time (training soldiers, building houses) which takes
some time (minutes, hours, even days). after time is up and soldier,
building is finished a browser should be refreshed to say - 'hey, your
request is done now !, you succesfully trained 5 soldiers and built one
house'.

So, it doesnt make sense to poll every 5 seconds if action of building a
house last 2 days ! Divide 2days by 5 seconds and you get number of
waisted requests to check if action is done.

was this enough clear for You ?

best regards

Aug 23 '07 #8

P: n/a
My first idea would be then to avoid polling at a particular fixed interval.
For example the AJAX call could return the next action with an estimated
time to complete (if 0 you can then can then perform the actual action). You
can now use this information to schedule your next AJAX call. If the user
does some action, you'll issue this call again (in case the new action would
be earlier than the previous one) etc...

In some cases the browser is just used to download a software especially if
a quick multiple players interaction is needed...

---
Patrice

"Piotr Nowak" <p.******@STRIPTHISwasko.pla écrit dans le message de news:
fa**********@nemesis.news.tpi.pl...
Patrice pisze:
>No the server can't reach a web client. This is always the client that
sends a request to the server and the server only responds to incoming
requests.

You could issue an AJAX call to the server that just tell if the client
should be updated. If not you have nothing more to do, if yes you can
issue your more complex ajax calls that would update parts of your
pages...

Youn may want to explain a bit more what you are trying to do...
--
Patrice

"Piotr Nowak" <p.******@STRIPTHISwasko.pla écrit dans le message de
news: fa**********@atlantis.news.tpi.pl...
>>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

Sure its quite generic problem.

Imagine you develop a online game, like ogame.
There's a lot action behind the scenes, players are making some actions
that take some time (training soldiers, building houses) which takes some
time (minutes, hours, even days). after time is up and soldier, building
is finished a browser should be refreshed to say - 'hey, your request is
done now !, you succesfully trained 5 soldiers and built one house'.

So, it doesnt make sense to poll every 5 seconds if action of building a
house last 2 days ! Divide 2days by 5 seconds and you get number of
waisted requests to check if action is done.

was this enough clear for You ?

best regards

Aug 23 '07 #9

P: n/a
Thanks, i have been thinking quite the same - time estimation.

regards
Aug 23 '07 #10

P: n/a
the browser can use ajax to poll the server for change. on the server
you should create a in memory collection to store the database change
event. then the ajax poll can be quick.

-- bruce (sqlwork.com)

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
Aug 23 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.