yes and no. First you missed a return false. Without that the page may
get reloaded.

#view
DIV(A('click me',_href='#',_id='parent',_onclick("ajax('clickback',
['parent'],':eval');return false")))

#controller
def clickback():
  return 'jQuery("#parent").html("%s");' %\
     SCRIPT("alert('hello world');")


now the jQuery returned by clickback will be executed on ajax but the
second the SCRIPT inside the html will never be executed. But you can
do:

#view
DIV(A('click me',_href='#',_id='parent',_onclick("ajax('clickback',
['parent'],':eval');return false")))

#controller
def clickback():
  return 'jQuery("#parent").html("whatever");alert("hello world");'

and now the alert will be executed.

Did this answer your problem?

the JS returned by the clickback

On Dec 23, 11:32 pm, weheh <[email protected]> wrote:
> Massimo, I appreciate the response, but am finding your answer very
> difficult to understand. In particular, I don't have a clue as to what
> your callback is doing. What is response.js? Why are you returning
> "hello world" when response.js is outputting "hello!". Is there any
> chance you can rewrite the original example at the top of this thread
> so that it would work? Thanks. - RG
>
> On Dec 24, 12:09 am, mdipierro <[email protected]> wrote:
>
> > It depends on how you do the ajax call:
>
> > I suggest you can use the web2py_ajax.html function:
>
> >    web2py_ajax_page(method,action,data,target)
>
> > For example in view
>
> > <button
> > onclick="web2py_ajax_page('POST','{{=URL('callback'}}}',null,'target');">click
> > me</button>
> > <div id="target">
>
> > and in controller
>
> > def callback():
> >     response.js = "jQuery('.flash').html('hello!').fadeIn();"
> >     return "hello world"
>
> > Massimo
>
> > On Dec 23, 7:19 pm, weheh <[email protected]> wrote:
>
> > > Let me try to state this more succinctly:
>
> > > How do I get a jQuery, which is created by a controller in response to
> > > an ajax call, to execute when loaded into it's target div?
>
>

Reply via email to