I dont know if this is the best approach, but I juste tested here and works.
I wanted to pass an array from jQuery to a controller.
<script>
var xyz= ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
$(function() {
$("body").click(function(event) {
ajax("{{=URL('default','mycontroller')}}"+"?array="+xyz,[],'target');
});
});
</script>
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.
<script>
var xyz= ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
args = xyz.join("/")
$(function() {
$("body").click(function(event) {
ajax("{{=URL('default','mycontroller')}}"+args ,[],'target');
});
});
</script>
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.
--