I trying to send un object from a view to controller (Web2py) in the same way that:
How to pass a JSON object to web2py using JQuery Ajax
The ajax part is:
var testObject = {};
testObject.value1 = "value1value!";
testObject.value2 = "value2value!";
var DTO = { 'testObject' : testObject };
var data = $.toJSON(DTO); //Using the toJSON plugin by Mark Gibson
$.ajax({
type: 'POST',
url: '/Myapplication/controllers/jsontest.json',
contentType: "application/json; charset=utf-8",
data: data,
dataType: 'json',
success: function(data){ alert('yay'); }
});
and the function jsontest is in /Myapplication/controllers/default.py I have
def jsontest():
import gluon.contrib.simplejson
data = gluon.contrib.simplejson.loads(request.body.read())
return dict()
Doing the same test I got a good string in var data = $.toJSON(DTO);
.I got the json.js in https://sites.google.com/site/jollytoad/json.js?attredirects=0
but nothing is transmited to the jsontest function. Can anyone explain me what is wrong? I thing my url could be bad ... etc Thanks for the answer...