JQuery - Appending to Serialize

前端 未结 2 1754
鱼传尺愫
鱼传尺愫 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: "", value: "" });
    submitForm(formData);
    

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

提交回复
热议问题