Hi, thanks for your post. I tried your suggestion, but still can't get it
to work, here is my new code:
*****************************************
{{extend 'layout.html'}}
<script>
$(function(){
$('.myactions li').click(function(){
elem = $(this);
url = elem.attr('data-url');
ajax(url, null, parse_my_data);
});
});
function parse_my_data(data){
$('target').append(data);
$('target').append(P('<hello>', XML('<b>world</b>')));
}
</script>
<ul class="myactions">
<li data-url="{{=URL('echo', vars=dict(id='1'))}}"> Do something </li>
</ul>
<br/>
<div id="target">should get updated</div>
**** Controller ****
def echo():
return request.vars.id
************************
Regards
Ann
On Thursday, 13 September 2012 19:23:19 UTC+1, rochacbruno wrote:
>
> The ajax function:
>
> ajax(
> url, # here you set a string to a complete url, it can include args
> and vars
> [], # form inputs, if you have a form on the page you can set
> ['name', 'email'] if you do not have a form set it to null
> target, # an id of any html element where you want the response to
> be inputed #mydiv or a function to be used as callback function(data){//do
> something})
> )
>
>
> NOTE: avoid the use of inline java script
>
> Example:
>
> {{extend 'layout.html'}}
> <script>
> $(function(){
> $('.myactions li').click(function(){
> elem = $(this);
> url = elem.attr('data-url');
> ajax(url, *null*, parse_my_data);
> });
> });
>
> function parse_my_data(data){
>
> $("#sometarget").html(data); # replaces the content of #sometarget
> with returned data
> $("#sometarget").append(data); # append data on the end of sometarget
> content
> $("#sometarget").prepend(data); # prepend data on the begin of the
> sometarget content
> // or you can do whatever you want with data as it can be json, txt or
> html
> }
> </script>
>
> <ul class="myactions">
> {{for item in collection:}}
> <li data-url="{{=URL('echo', vars=dict(id=item.id))}}"> Do something
> </li>
> {{pass}}
> </ul>
>
--