Gandalf
Gandalf

Reputation: 13683

Posting additional data alongside serialized form data

I want to post some additional data alongside serialized data i got from user form input.

For instance,

$.post('update.php', $("#theform").serialize(),{cposition:swidget}, function(data) {

});

This does not post the additional post.How am i supposed to post the additional data?.

Upvotes: 0

Views: 228

Answers (3)

jcubic
jcubic

Reputation: 66490

You can append something to the end of serialized string.

$.post('update.php', $("#theform").serialize() + '&cposition:swidget', function(data) {

});

Upvotes: 1

David Hedlund
David Hedlund

Reputation: 129792

The jQuery serialize function yields its values in the &key=value format. It does this using $.param internally. You would be able to append your own values in the same manner:

$.post('update.php', [$('#theform').serialize(), $.param({cposition:swidget})].join('&'), function(data) { ... });

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

you can do:

var data = $('#theform').serializeArray();
data.push({cposition: swidget});
//then
$.post('update.php', data, function(data) {

});

Upvotes: 1

Related Questions