[web2py] Re: How to pass an array from jQuery to controller

2014-07-02 Thread Noel Villamor
Nice one Chris and thanks for reviewing this post. Web2py has indeed come a 
long way from 2 years ago and is worthy of a revisit. Cheers!

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to pass an array from jQuery to controller

2011-09-04 Thread Anthony
On Sunday, September 4, 2011 8:01:16 PM UTC-4, Noel Villamor wrote:
>
>
> Thanks for that very helpful snippet Bruno. 
>
> Just a follow-up, will it be possible for the 'target' parameter below 
> be a jQuery function? I wanted to do some further processing on the 
> browser side when callback returns. 
>
> ajax("{{=URL('default','mycontroller')}}"+args ,[],'target');
>

If you set target to ':eval' and have the function return some javascript, 
the javascript will be executed upon return. See 
http://web2py.com/book/default/chapter/10#Eval-target.

Anthony 


[web2py] Re: How to pass an array from jQuery to controller

2011-09-04 Thread Noel Villamor

Thanks for that very helpful snippet Bruno.

Just a follow-up, will it be possible for the 'target' parameter below
be a jQuery function? I wanted to do some further processing on the
browser side when callback returns.

ajax("{{=URL('default','mycontroller')}}"+args ,[],'target');



On Aug 31, 6:18 pm, Bruno Rocha  wrote:
> I dont know if this is the best approach, but I juste tested here and works.
>
> On Wed, Aug 31, 2011 at 2:17 AM, Noel Villamor  wrote:
> > I wanted to pass an array from jQuery to a controller.
>
> > 
> > var xyz= ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
> > $(function() {
> >     $("body").click(function(event) {
>
> >  ajax("{{=URL('default','mycontroller')}}"+"?array="+xyz,[],'target');
>
>     });> });
> > 
>
> > the above will call this url:
>
> /default/mycontroller?array=['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
>
> > def mycontroller():
> >    # Here, I wanted to receive xyz as an array.
>
>       myarray = eval(request.vars.array)
>
> the above will receive the string and evaluate as a Python list.
>
> (BUT, BE CAREFUL!! it can be used to crash your app)
>
> another solution may be better than the above, is to split the array as args
> and pass it separated.
>
> 
>
> var xyz= ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
> args = xyz.join("/")
>
>  $(function() {
>      $("body").click(function(event) {
>             ajax("{{=URL('default','mycontroller')}}"+args ,[],'target');
>
>      });
>
> });
>
> 
>
> the url will be called as
>
> /default/mycontroller/Sun/Mon/Tue/Wed/Thu/'Fri/Sat
>
> in controller
>
> def mycrontroller():
>
>     array = request.args
>     array[0] # "Sun"
>
> The second approach is better ans safe.
> --
>
> --
> Bruno Rocha
> [ About me:http://zerp.ly/rochacbruno]
> [ Aprenda a programar:http://CursoDePython.com.br]
> [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
> [ Consultoria em desenvolvimento web:http://www.blouweb.com]


[web2py] Re: How to pass an array from jQuery to controller

2011-08-30 Thread pbreit
I think you might want the Ajax function:
http://web2py.com/book/default/chapter/10#The-ajax-Function


[web2py] Re: How to pass an array from jQuery to controller

2011-08-30 Thread Noel Villamor
Please ignore the above post, as it was submitted prematurely. If a
moderator is around, please delete the post. Thank you.