4

I have a form that I can post all the data in the ajax call like this:

data: $("#myform).serialize(),

But in the function, I set a variable to be be posted

That variable is var favorite = true; or var favorite = false;

It will post that variable if I do this:

var favorite = true;
var first_name = $("myform input[name=first_name]").val();
data: { favorite: favorite, first_name: first_name, etc ... }

But I was wondering if i could something like:

data: $("#myform).serialize + {favorite: favorite}

Its not a big deal if thats not possible, I am just clean up the function.

Brad
  • 12,054
  • 44
  • 118
  • 187

1 Answers1

4

The serialize() method return a parameter string, so you could just use string concatenation like

data: $("#myform").serialize() + '&favorite=' + favorite
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531