在 sencha 中,AJAX 总是成功的,但在 grails 中,每当我尝试恢复他时都会失败。它应该恢复def data = params.data
,并且def data = params
没有工作。
sencha 中的控制器(保存时)
onSave: function(button, e, eOpts) {
var name = Ext.getCmp('name').getValue();
var description = Ext.getCmp('description').getValue();
var data = {};
data.name = name;
data.description = description;
Ext.Ajax.request({
type: 'POST',
contentType:'application/json',
dataType: 'jsonp',
data: data,
crossDomain: true,
url: 'http://localhost:8080/TryIt/product/newProduct',
success: function(response, opts) {
console.log('server-side success with status code ' + response.status);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
},
error: function(msg){
alert(msg);
}
});
grails中的控制器
def newProduct() {
def data = JSON.parse(data)
def newP = new Product(name: data.name, description: data.description)
if (newP) {
newP = newP.save(flush: true)
println "saved!"
println data.name
println data.description
} else {
println "error"
}
return result as JSON
}
问题是,如何恢复交给 grails 的数据?哦,是的,js 和 jquery 就像彩虹和蝴蝶一样(效果很好)。