2

I use a jQuery plugin called jscroller, which uses jquery.ajax to make ajax calls. I need to pass in all parameters from a search form, and deliver them to mvc controller, and I think the best way is to put in 'data' field the following expr':

$('#formId').serialize();

My problems is that I need to pass, along with the form values, a 'page' value which is being changed with each call.

How can I put the page value, along with the 'serialize' expression in 'data' field, or is there really another more efficient way to do it?

Tal l
  • 265
  • 1
  • 3
  • 12

3 Answers3

6

I think

var formdata = $('#formId').serialize();
data: (formdata ? formdata + "&" : "") + "page=" + pageId

will solve your problem

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

You can create a new FormData and just add the parameter on that variable too

var formData = new FormData(); 
formData.append('pageId', pageId);

var your_form = $('#formId').serializeArray();
$.each(your_form,function(key,input){
   formData.append(input.name,input.value);
});

$.ajax({
    url: 'url_here',
    data: formData,
    contentType: false,
    processData: false,
    type: 'POST'
});

so at MVC controller you will be able to access like

var pageId = Request.Form.Get("pageId");
Antonio Correia
  • 1,093
  • 1
  • 15
  • 22
0

I know I'm super late but the code below worked for me.

var data = $('#Form').serialize() + '&test=' + number;
$.ajax({
    ....
    data: data;
Jimmy Oku
  • 11
  • 2