The simplest solution is that you get generic.load from  1.80.1 and
you

replace

function refreshWidget() {
   ajax('refresh_widget', [], 'mywidget');
}

with

function refreshWidget() {
   ajax('refresh_widget.load', [], 'mywidget');
}


On 13 Lug, 16:46, Tomas Pelka <tompe...@gmail.com> wrote:
> Thank you very much Adi, but rpoblem is that refreshWidget is called
> only once. And after that page looks like in attached screenshot.
>
> My ajax function is here:
> function ajax(u,s,t) {
>    var query="";
>    for(i=0; i<s.length; i++) {
>       if(i>0) query=query+"&";
>
> query=query+encodeURIComponent(s[i])+"="+encodeURIComponent(document.getElementById(s[i]).value);
>    }
>    jQuery.ajax({type: "POST", url: u, data: query, success:
> function(msg) { if(t==':eval') eval(msg); else
> document.getElementById(t).innerHTML=msg; } });
>
> }
>
> Cheers Tom.
>
> On 07/09/2010 07:01 AM, Adi wrote:
>
>
>
> > Some frameworks have active data widgets - the widget updates whenever
> > data changes. I'm not sure how exactly it can be implemented in
> > web2py, but something like this should work:
>
> > View (.html file):
> > ------------------------
> > <div id="mywidget">{{=mywidget}}</div>
> > <script>
> > setTimeout(refreshWidget, 10000); // calls refreshwidget every 10
> > seconds
> > function refreshWidget() {
> >     ajax('refresh_widget', [], 'mywidget');
> > }
> > </script>
>
> > Controller (.py file)
> > ---------------------------
> > def refresh_widget():
> >     # logic to generate widget
> >     return dict(mywidget=mywidget)
>
> > Explanation:
> > Every 10 seconds there's an ajax call to controller's refresh_widget,
> > which generates the HTML for the updated view that you want to show
> > inside the mywidget tags (like list of elements). This HTML is placed
> > inside the mywidget tag.
>
> > This is the simplest way to solve this problem that I can think of,
> > and this is not efficient because even if your data has not changed,
> > you'll still be polling the server every 10 seconds. But this should
> > work!
>
> > On Jul 9, 1:32 am, Tomas Pelka<tompe...@gmail.com>  wrote:
> >> Hi all,
>
> >> Im trying to create widget (lets say list of elements) which should by
> >> updated asynchronously through ajax. I don't get all the ajax examples
> >> in web2py book for example. Those examples only deals with some action,
> >> like on click, on mouse move, on sbutton submit or so. I need something
> >> like check if queue (source of data) have anything to provide or simple
> >> use a timer and reload widget every e.g. 10 sec.
>
> >> Thanks for advices. Please let me know if anything was unclear/wrong
> >> described.
>
> >> --
> >> Tomas Pelka
>
> --
> Tomas Pelka
>
>  Screenshot.png
> 195KVisualizzaScarica

Reply via email to