SoFunction
Updated on 2024-07-16

jQuery ajax use serialize method to submit form data example

jQuery ajax data in the form of key/value pairs (Key/Value) sent to the server, using ajax submit form data can be jQuery ajax serialize() method form serialized to key-value pairs (key1=value1&key2=value2...) after submission. serialize() method uses standard URL-encoded encoding to represent a text string. The serialize() method uses standard URL-encoded encoding for text strings. The following is an example of using serialize() to serialize a form:
Copy Code The code is as follows.

$.ajax({
   type: "POST",
   url: ajaxCallUrl,
   data: "Key=Value&Key2=Value2",
   success: function(msg){alert(msg);}
 });

ajax serialize():
Copy Code The code is as follows.

$.ajax({
         type: "POST",
         url:ajaxCallUrl,
data:$('#formID').serialize(),// the form to submit
         success: function(msg) {alert(msg);}
     });

Example: