I have used this example but request.vars is empty, I cannot get the json 
string in controller.

In view:

{{extend 'layout.html'}}
<h1>Template default/jsontest.html</h1>
{{=BEAUTIFY(response._vars)}}

<script>
  $(document).ready(function(){
  $.ajax({
    type: 'POST',
    url:'http://127.0.0.1:8000/MFREG/default/jsontest.json',
    contentType: "application/json; charset=utf-8", 
    data: {'key':'value','key2':'value2'},
    dataType: 'json',
      success:  function(data){  alert(data); }
});
  });
</script> 


In controller:

def jsontest():
    datos = str(request.post_vars)
    return locals()

What I get:

<https://lh3.googleusercontent.com/-hgL-ctSIo8s/VI3OZsdXkEI/AAAAAAAAAp4/i2gSvKR9vkg/s1600/Selecci%C3%B3n_802.png>
So the json data is not stored in request.post_vars.

I don't know what is wrong.

El viernes, 11 de enero de 2013 16:34:00 UTC+1, Anthony escribió:
>
> The data will be in request.vars, not request.args.
>
> Anthony
>
> On Friday, January 11, 2013 10:28:27 AM UTC-5, yn yn wrote:
>>
>> Thanks for the answer...
>> Ok 
>> I have tested jQuery.post('{{=URL('default', 
>> 'testpost')}}',{'key':'hello'})
>>
>> where in default.py there is a def:
>>
>> def testpost():
>>     import os
>>     data = request.args(0)
>>     myfile = os.path.join(request.folder, 'static', 'file1.txt')
>>     f = open(myfile, "w")       
>>     f.write(data)
>>     f.close()
>>     return dict()
>>
>> I can open the file1.txt but nothing is writing there. I think 'hello' is 
>> not transmited ... isn'it it? do you know what is wrong?
>>
>>
>>
>> El viernes, 11 de enero de 2013 15:13:29 UTC+1, Massimo Di Pierro 
>> escribió:
>>>
>>> I suggest using jquery.post
>>>
>>> jQuery.post('{{=URL('testfunction')}}',{'key':'value'})
>>>
>>> {'key':'value'} is a js dictionary, can be anything you like and tehy 
>>> will be passed as vars properly escaped.
>>>
>>>
>>>
>>>

-- 
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.

Reply via email to