Grails: where does request.JSON come from, and how do I put things there with jQuery's .ajax() or .post()?
I have the same trouble like you few days ago.
For me - the solution was to use jQuery.ajaxSetup
to set the default value for ajax content type.
$(function() { $.ajaxSetup({ contentType: "application/json; charset=utf-8" });}
With this you could use $.ajax
or $.post
to transfer your JSON to the controller and use it like that:
def yourJSON = request.JSON
I dont't know why the 'contentType' option within $.ajax
and $.post
was ignored during my tests.
Had a similar problem also but didn't need to use ajaxSetup, just needed to set contentType:
$.ajax({ method: "POST", url: "/api/bar" data: JSON.stringify({a:true}), contentType:"application/json; charset=utf-8", dataType: "json", success: function(){ console.log("args: %o", arguments); }});