I highly recommend jQuery’s serialize() method for handling forms.

Origin 2377837207

Hello, this is Bono.

Form handling is a very basic aspect of web technology, but it can be quite difficult to handle because of the many restrictions and inflexibility.

Here, we introduce a useful method in jQuery.

serialize()

This will allow you to specify the

The data of all form elements (input, select, text, etc.) in the form can be combined into a series of data for transmission.

The basic form is this.

$("input#hoge").click(function(){
    var disp = $("#form").serialize();
    $("#foo").text(disp);
});

Serialize means to convert parameters and values into a string of beads of data, such as par1=AAA&par2=BBB&par3=CCC&....

For example, you can use it like this. This is how it works when form data is sent to ajax.
Parameters can also be added by connecting & to the form data, as in the last line.

$.ajax({
    type : 'POST',
    url : 'url',
    data : $('#form').serialize() + "&par1=1&par2=2&par3=3"
}

By the way, even if other unrelated tags are mixed in the form element, it will not affect the data to be sent.
Reference.