Javascript 从Ajax调用控制器获取参数
我的ajax调用正在传递以下数据:Javascript 从Ajax调用控制器获取参数,javascript,jquery,ajax,grails,Javascript,Jquery,Ajax,Grails,我的ajax调用正在传递以下数据: var quoteParams ={check:true,startDate:date} $.ajax({ type: "POST", url: "check/save", data: {orderForm : gatherOrderDetails(), quoteForm : quoteParams } , // GatherORderDetails will get all the form in
var quoteParams ={check:true,startDate:date}
$.ajax({
type: "POST",
url: "check/save",
data: {orderForm : gatherOrderDetails(), quoteForm : quoteParams } , // GatherORderDetails will get all the form input values from a form
success: function(msg) {
alert(msg.d);
},
error: function(msg) {
alert('error');
}
});
因此,在我的控制器中,我希望将“orderform”和“quoteForm”作为类的对象。类是类ordersForm和类quotesForm
def save(ordersForm orderForm,quotesForm quoteForm){
//now i need to save all the details obtained from 'orderform' and 'quoteform' after procerssing them in database.
}
但我得到一个错误,即参数无效。只需定义如下保存操作:
def save() {
// do stuff with orderForm
params.orderForm
// do stuff with quoteForm
params.quoteForm
}
另外,看看哪种方法可以大大简化事物的持久性方面
不确定javascript gatherOrderDetails()函数在做什么,但如果只需要提交所有表单元素,则可以使用
我想说的是,您应该通过
request.JSON
访问它:
def save() {
def json = request.JSON
doSomething json.orderForm
doSomethingElse json.quoteForm
}
刚改了,值是多少您通过ajax传递的数据是多少?我只是使用了param,然后将其设置为类new object的instace
def save() {
def json = request.JSON
doSomething json.orderForm
doSomethingElse json.quoteForm
}