Ajax page update

150 views
Skip to first unread message

David J.

unread,
May 19, 2011, 9:29:30 AM5/19/11
to web...@googlegroups.com
I was wondering how can I PUSH updates to a page using Ajax.

On our orders page as orders come in I want the page to automatically be
updated;

Currently I just refresh the page every N seconds; but I thought it
could be made more efficient.

Like some sort of event notification system.

Thanks in advance for any advice on this.


Ross Peoples

unread,
May 19, 2011, 9:56:00 AM5/19/11
to web...@googlegroups.com
Polling with JavaScript is the most common way. However, there is a way to use comet, which allows the server to push updates immediately to clients, but I've never used that, it's still experimental, and may be difficult to set up. Unless you need instant updates (like with an instant messaging app), then sticking with JS polling, checking for updates every 10, 20 seconds or so should be sufficient.

Anthony

unread,
May 19, 2011, 10:05:52 AM5/19/11
to web...@googlegroups.com
The simplest approach would probably be ajax short polling (i.e., an ajax request every n seconds). If the orders page is just an administrative page with a small number of simultaneous users, that's probably fine. If that's not adequate, you could look into comet type solutions. web2py includes a WebSockets implementation in /gluon/contrib/comet_messaging.py (http://code.google.com/p/web2py/source/browse/gluon/contrib/comet_messaging.py). That doesn't work in all browsers, but it can be adapted to fall back to other methods using Socket.IO -- see http://greg.thehellings.com/2011/04/web2py-websockets-and-socket-io-part-i-basic-display/.
 
Anthony

VP

unread,
May 19, 2011, 10:25:43 AM5/19/11
to web2py-users
Is there a guide for a clean and sweet way to implement these types of
polling? Like using jquery?

Thanks.


On May 19, 9:05 am, Anthony <abasta...@gmail.com> wrote:
> The simplest approach would probably be ajax short polling (i.e., an ajax
> request every n seconds). If the orders page is just an administrative page
> with a small number of simultaneous users, that's probably fine. If that's
> not adequate, you could look into comet type solutions. web2py includes a
> WebSockets implementation in /gluon/contrib/comet_messaging.py (http://code.google.com/p/web2py/source/browse/gluon/contrib/comet_mes...).
> That doesn't work in all browsers, but it can be adapted to fall back to
> other methods using Socket.IO -- seehttp://greg.thehellings.com/2011/04/web2py-websockets-and-socket-io-p...
> .

VP

unread,
May 19, 2011, 10:45:34 AM5/19/11
to web2py-users
Follow up questions: how do I do these in web2py?

- Ajax submission. After I submit a form, the message is updated on
the page via ajax (the page is not reloaded)?

- If I have a section that needs to be updated periodically (by
calling a controller function), how do I do it using ajax w/o loading
the page?

Thanks.

Chris May

unread,
May 19, 2011, 10:54:49 AM5/19/11
to web2py-users
I thought I read of a way of using jQuery for something like this
using its deferred object. (http://api.jquery.com/category/deferred-
object/)

Sorry I can't be more specific, but I hope it helps.

VP

unread,
May 20, 2011, 1:26:23 PM5/20/11
to web2py-users
Thank you. I will look into this.
Reply all
Reply to author
Forward
0 new messages