JQuery - Appending to Serialize

前端 未结 2 1755
鱼传尺愫
鱼传尺愫 2020-12-29 23:16

I am trying to figure out how to append two more values to the serialize method in JQuery. I have the following code to submit a form with ajax and have two more variables t

相关标签:
2条回答
  • 2020-12-29 23:31

    If you change serialize() to serializeArray() you can push values into the array :

    var formData = $('#contact_form').serializeArray();
    formData.push({ name: "<something>", value: "<somevalue>" });
    submitForm(formData);
    

    The data can still be sent in the same way as you would with the serialize() method, using the $.ajax() method

    0 讨论(0)
  • 2020-12-29 23:33

    You can add new values by appending to your variable:

    formData += '&var1=blah&var2=blah';
    
    0 讨论(0)
提交回复
热议问题