0

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?.

Gandalf
  • 1
  • 29
  • 94
  • 165
  • possible duplicate of [How do I modify serialized form data in jquery?](http://stackoverflow.com/questions/5075778/how-do-i-modify-serialized-form-data-in-jquery) – MrCode Jun 11 '13 at 07:14

3 Answers3

1

you can do:

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

});
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
1

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) { ... });
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
1

You can append something to the end of serialized string.

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

});
jcubic
  • 61,973
  • 54
  • 229
  • 402