append variable to be posted to ajax serialized data

Viewed 2324

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.

1 Answers
Related