How do I get my ajax key/values to be recognized in the "params" object in a controller?
I'm trying to send some data via JQuery ajax to a grails controller
Here's the data
var data =
{'status':"SOMETHING",
'scheduleDate':remindDate.toString("MMMM dd yyyy h:mm:ss tt"),
'dueDate':parsedDate.toString("MMMM dd yyyy h:mm:ss tt"),
'owner':"SOMETHING ELSE",
'type':'concierge',
'notes':"NOTES",
'party': "SOME PARTY VALUE"
};
...and here's the Ajax call:
$.ajax({
url: '/concierge/todo/add',
type: 'POST',
data: JSON.stringify(data),
dataType: 'json',
beforeSend: function(x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
success: function(result) {
开发者_JAVA百科 refreshMyUI(null);
}
});
});
I can get this working if I don't POST the data but use a GET. But if I post, the data comes in like this:
[{"status":"do","scheduleDate":"February 06 2011 3:26:07 PM","dueDate":"February 06 2011 3:26:07 PM","owner":"3","type":"concierge","notes":"hoooo","party":"3"}:, action:add, controller:todo]
This is the value of "params" when the controller is called. Note that my parameters are not merged propertly with the other parameters; it's as if the entire string is a "key" on the LHS of the colon, and there's nothing on the other side.
What am I doing wrong here?
Get rid of JSON.stringify
and have just data: data
精彩评论