In the view you have to do something like
... onclick="ajax('{{=URL(r=request,f='callback')}}', [], 'itemize')"
and in the controller
def callback():
return self.itemize0(db.qpac,nitems=12)
You cannot mix Python code and JS.
On Nov 5, 4:51 pm, Wes James <[email protected]> wrote:
> Where can I find a code snippet that shows how to return the results
> of a function via ajax in w2p?
>
> thx,
>
> -wes
>
> On Thu, Nov 5, 2009 at 3:46 PM, mdipierro <[email protected]> wrote:
>
> > OK then
>
> > ajax('{{=self.itemize0(db.qpac,nitems=12)}}', [], 'itemize')"
>
> > is wrong because the first argument of ajax should be the URL that
> > returns self.itemize0(...), it cannot be the HTML generated by the
> > function.
>
> > On Nov 5, 4:27 pm, Wes James <[email protected]> wrote:
> >> No, it's t2.itemize with some of my changes. I'm trying to get the
> >> results back from t2.itemize and put it in a div with ajax.
>
> >> -wes
>
> >> On Thu, Nov 5, 2009 at 3:25 PM, mdipierro <[email protected]> wrote:
>
> >> > The first argument of ajax should be a URL.
> >> > I do not know what self.itemize0 is. Does it generate a URL?
>
> >> > On Nov 5, 4:03 pm, Wes James <[email protected]> wrote:
> >> >> I have this:
>
> >> >> INPUT(_type='button', _value='search',_onclick="ajax('', [],
> >> >> 'itemize')")
>
> >> >> reload page - works fine:
>
> >> >> Then change to this:
>
> >> >> INPUT(_type='button',
> >> >> _value='search',_onclick="ajax('{{=self.itemize0(db.qpac,
> >> >> nitems=12)}}', [], 'itemize')")
>
> >> >> I then get:
>
> >> >> SyntaxError: unexpected character after line continuation character
>
> >> >> -wes
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---