Re: [web2py] Beginner trying to adapt the Chapter 11 ajax function 'echo' example

2012-09-17 Thread AnnG
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('bworld/b')));  
}
/script

ul class=myactions
li data-url={{=URL('echo', vars=dict(id='1'))}} Do something /li
/ul
br/
div id=targetshould 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
  

-- 





Re: [web2py] Beginner trying to adapt the Chapter 11 ajax function 'echo' example

2012-09-17 Thread Bruno Rocha
you need to use # on id selectors  $(#selector_id)

function parse_my_data(data){
   $('*#*target').append(data);
   $('*#*target').append(P('hello', XML('bworld/b')));
}

-- 





Re: [web2py] Beginner trying to adapt the Chapter 11 ajax function 'echo' example

2012-09-17 Thread Ann Gledson
That works. THANKS!


On Mon, Sep 17, 2012 at 8:16 PM, Bruno Rocha rochacbr...@gmail.com wrote:


 you need to use # on id selectors  $(#selector_id)

 function parse_my_data(data){
$('*#*target').append(data);
$('*#*target').append(P('hello', XML('bworld/b')));
 }

 --





-- 





Re: [web2py] Beginner trying to adapt the Chapter 11 ajax function 'echo' example

2012-09-13 Thread Bruno Rocha
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

--