I am trying to format POST JSON data from Javascript (using Prototype) in Grails. My Javascript Code:
var JSONObject = new Object;
JSONObject.id = "23";
JSONObject.name = "Test 1";
JSONstring = JSON.stringify(JSONObject);
var url = "${createLink(controller:'testController', action:'receiveJson')}";
new Ajax.Request(url, {
method:'post',
contentType:'application/json',
parameters:JSONstring,
asynchronous:true,
onSuccess: function (req) {
sendInfoResponse(req.responseText);
}
});
and my Grails controller code:
def receiveJson = {
def json = request.JSON;
}
However, in my tests, the 'json' variable seems empty. I would be so grateful if anyone could explain what I am doing wrong. Many thanks.
source
share