1

I send data with my form through jquery $.post to some PHP page, but now i want to add some extra data to this sent package. Here is my code:

    $.post("/settings/filter", $("#filter_form").serialize() , function(data,status,xhr)
    {
            my_data = data;

    }) 

I've tried to change it into

    $.post("/settings/filter", {$("#filter_form").serialize(), extra_variable:'extra1'} , function(data,status,xhr)

but it's wrong, how to do it?

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
pawel
  • 5,976
  • 15
  • 46
  • 68

1 Answers1

4

You can use string concatination

$("#filter_form").serialize() + '&extra_variable=extra1'

It is because $("#filter_form").serialize() returns a string representation of the form like params1=x&params2=y, if the data is string then jQuery will not do any more processing on the data. so you need to do a string concatenation to append the extra values you need.

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