On Tuesday, October 25, 2011 12:14:31 PM UTC-4, Cliff wrote:
>
> I had some trouble getting LOAD to work, so I used something like
> this:
>
> In the html:
>
> <div id="variable_text">
> </div>
> <a href=# id="click_me">Click here</a>
>
> In the javascript:
> $document.ready(function(){
> $('#click_me').live('click', function(){
> ajax('make_variable_text', [], ':eval');
> });
> });
>
> In the controller:
> def make_variable_text():
> # do stuff to create text
> return "$('#variable_text').html('the text you just created');"
>
Instead, you can do ajax('make_variable_text', [], 'variable_text') and
return 'the text you just created', and the ajax() function should
automatically put the returned text into the 'variable_text' div for you.
Even easier, you can use the A() helper with the 'callback' argument and
avoid having to set up your own click event handler
(http://web2py.com/book/default/chapter/05#Built-in-Helpers).
Anthony