Pooya
Pooya

Reputation: 1558

How to add post parameters to $.ajax and $.ajaxSubmit

I used the ajax method of jquery for my forms. but now I need to add a field to the function.

how can I have my forms fields and my new post parameter.

        var frm = $(n);
        $.ajax({
                type: frm.attr('method'),
                url: frm.attr('action'),
                //contentType:frm.attr('enctype'),
                data: frm.serialize(),
                success: function (data) {
                    $(dataform).html(data);
                    $(des).html('');
                    $("button[type='submit']").attr('disabled',null);
                }
        });

the data parameter should be like this:

data: frm.serialize() + {'foo':'bar'}

thanks in advance.

Upvotes: 0

Views: 1410

Answers (2)

rajesh kakawat
rajesh kakawat

Reputation: 10896

try something like this

data: frm.serialize()+'&foo=bar',

Upvotes: 0

Collin Grady
Collin Grady

Reputation: 2243

.serialize() returns a string of parameters like you'd see in a querystring, so just add on + "&foo=bar"

Upvotes: 1

Related Questions