1

I have the following code:

 $.post('/Calendar/Add', $("#calendarForm").serialize(), function (data) {

 });

and i want to add another piece of data in addition to all of the items in the #calendarForm.

so lets say i want to append an additional key value pair to the querystring:

  personId=223

I would rather not add extra hidden inputs into the calendarForm as that is what i am doing now and its kind of messy. Is there any easy way to add an additional piece of data besides all of the value in the calendarForm when i call this post ?

I tried something like this:

 $.post('/Calendar/Add', $("#calendarForm").serialize() + "&personId=223", function (data) {

 });

but that didn't seem to work?

leora
  • 188,729
  • 360
  • 878
  • 1,366

2 Answers2

2

Try using serializeArray

var data = $('#myFormName').serializeArray();
data.push({name: 'myParamName', value: 'MyParamValue'});

Update1:

You can use following code in $.post:

$.post('/Calendar/Add', data, function (data)    
{});

For more information have look at this.

Bhushan
  • 6,151
  • 13
  • 58
  • 91
0

you can do it like bellow

$.post('/Calendar/Add', { personId: 223,calendarForm: $("#calendarForm").serialize() },
         function (data) { });
Jyoti Prakash
  • 1,180
  • 8
  • 9