Prabin Poudel
Prabin Poudel

Reputation: 73

Get params from Ajax Call in controller

my ajax call is passing following data:

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');
        }

    });

So in my controller i want to get the 'orderform' and ' quoteForm' as object of class.the class are Class orderssForm and Class 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.

}

But i get error that the params is invalid.

Upvotes: 0

Views: 84

Answers (2)

injecteer
injecteer

Reputation: 20699

I'd say, you should access that via request.JSON:

def save() {
    def json = request.JSON
    doSomething json.orderForm
    doSomethingElse json.quoteForm 
}

Upvotes: 0

Mike W
Mike W

Reputation: 3932

Just define your save action like this:

def save() {
    // do stuff with orderForm
    params.orderForm

    // do stuff with quoteForm
    params.quoteForm 
}

Also take a look at data binding which can massively simplify the persistence side of things.

Not sure what your javascript gatherOrderDetails() function is doing but if you just need to submit all form elements you can use serialize e.g.

var data = $('form').serialize();

Upvotes: 1

Related Questions