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>

-- 



Reply via email to