request.vars value are plain string. If you pass a json as a var for instance ?input=JSON_CONSTRUCT
You will have to use simplejson.load(request.vars.input) To restore the plain text JSON_CONSTRUCT from the ajax call into a JSON object. Here doc for python lib json : https://docs.python.org/2/library/json.html But the same applied for simplejson that is better. Richard On Fri, Feb 20, 2015 at 1:19 PM, clara <[email protected]> wrote: > Hello, > > I am making an Ajax call and calling a controller with the json data I > need to process in the controller. > > The problem I am having (and I am sure the answer will be simple and I > will hate myself for the silly question ) is that if I select > request.vars.input, its value is not a json object anymore so a loads > method will fail. It is a string object and if I try to eval(it) I get an > error. So even when the data is right there I can not use it in the > controller. > Any ideas will be more than welcome! > > (The controller and its print outs are shown bellow.) > > Thanks, > Clara > > def test(): > print "test called" > print "test called" > print 'request.vars' > print request.vars > print 'request.vars.input' > > Here is what the controller prints out: > > test called > request.vars > <Storage {'input': '[{"the_owner":1,"category":1,"name":"La marcha del > oro","price":44.45,"id":1,"quantity":100},{"the_owner":3,"c > ategory":3,"name":"Toy > Story","price":34.56,"id":2,"quantity":23},{"the_owner":2,"category":2,"name":"La > Sirenita","price":56.67," > > id":3,"quantity":10},{"the_owner":null,"category":null,"name":null,"price":null,"id":null,"quantity":null}]'}> > request.vars.input > [{"the_owner":1,"category":1,"name":"La marcha del > oro","price":44.45,"id":1,"quantity":100},{"the_owner":3,"category":3,"name":"T > oy > Story","price":34.56,"id":2,"quantity":23},{"the_owner":2,"category":2,"name":"La > Sirenita","price":56.67,"id":3,"quantity":10} > > ,{"the_owner":null,"category":null,"name":null,"price":null,"id":null,"quantity":null}] > > > -- > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

