Hiiii again :)

I think the problem is this

Instead of 

request.vars.items[json1]
>

use this

request.vars['items[json1]']
>

because the var is 'items[json1]' requests.vars.items[json1] will look for 
the key 'json1' in the dict var items and there is no items var only a 
'items[json1]' var that's why you need to use ['items[json1]'] and not 
items[json1]

Regards

El miércoles, 20 de noviembre de 2019, 23:12:45 (UTC+1), Patito Feo 
escribió:
>
> Paco here is the reponse:
>
>
>    1. {vars: {…}, respuesta: "noexiste"}
>       1. respuesta: "noexiste"
>       2. vars: {tarea: "solicitudguardar", items[json1]: "[1,2,3]"}
>       3. __proto__: Object
>    
>
>
> Thanks in advance,
>
>
> El miércoles, 20 de noviembre de 2019, 16:39:22 (UTC-5), Paco Bernal 
> escribió:
>>
>> Hi,
>>
>> Try this, write down at the begin of the controller
>>
>> print request.vars
>>>
>>
>> you will see how the controller receives the information and then you 
>> will know if it's a js problem or a server side problem.
>>
>> with your code what the controller receives is 
>>
>> <Storage {'tarea': 'solicitudguardar', 'items[json1]': 
>>> '{"make":"Ford","model":"Mustang","year":1969}'}>
>>>
>>
>> you don't need to use  json.loads, you just need this
>>
>>>
>>> mydata = request.vars['items[json1]']
>>> print mydata
>>> {"make":"Ford","model":"Mustang","year":1969}
>>>
>>
>> Regards from spain Ugly Duckling :)
>>
>> El miércoles, 20 de noviembre de 2019, 18:08:03 (UTC+1), Patito Feo 
>> escribió:
>>>
>>> Hi,
>>>
>>> Ive been trying to pass an object with keys to the controller. But i 
>>> havent been able to extract the request.vars.
>>>
>>> Here is my view:
>>>
>>> var Cars = {}
>>> Cars.make = 'Ford';
>>> Cars.model = 'Mustang';
>>> Cars.year = 1969;
>>>
>>> $.post( "{{=URL('default', 'transcriptor')}}", //request.post_vars.json1
>>>    {     
>>>          tarea: 'solicitudguardar', items: { json1: JSON.stringify( Cars 
>>> ) }
>>>    }, )
>>>
>>>
>>> Here is my function:
>>>
>>> elif request.vars.tarea == 'solicitudguardar':
>>>
>>>    var = json.loads ( request.post_vars.items[json1] )
>>>        
>>>        
>>>
>>> Here is one of the errors i got:
>>>
>>> global name 'json1' is not defined
>>>
>>>
>>> I dont understand why the array object is not being process as a json 
>>> array in controller. 
>>>
>>> Any help will be much appreciated.
>>>
>>>
>>> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/1ae3295f-cc6c-4863-ab6e-a608f84242fa%40googlegroups.com.

Reply via email to