Definition and usage
The serialize () method creates a URL-encoded text string by serializing the form value.
You can select one or more form elements (such as input and/or text boxes), or the form element itself.
The serialized value can be used in the URL query string when generating an AJAX request.
Grammar
$ (selector). Serialize ()
<HTML><Head><Scripttype= "Text/javascript"src= "/jquery/jquery.js"></Script><Scripttype= "Text/javascript">$ (document). Ready (function(){ $("Button"). Click (function(){ $("Div"). Text ($ ("form"). Serialize ()); });});</Script></Head><Body><formAction="">First name:<inputtype= "text"name= "FirstName"value= "Bill" /><BR/>Last Name:<inputtype= "text"name= "LastName"value= "Gates" /><BR/></form><Button>Serialization of form values</Button><Div></Div></Body></HTML>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title><Scripttype= "Text/javascript"src= "Js/jquery-1.8.3.min.js"></Script><Scripttype= "Text/javascript">$(function(){ $(": Submit"). Click (function() {alert (1); Alert ($ ("form"). Serialize ()); }); /*$ ("#username"). blur (function () {var values = $ ("#username"). Val (); if (values== "") {alert ("User name cannot be empty, please re-enter"); } $.ajax ({url: "formservlet?username=" +values,//Request address//data:values,//data to be sent type: "Get",//Requested Mode dataType: "Text",//server response data type JSON text XML HTML script success:function (DATA,STATUS,XHR) {//successful post execution The code//alert (data); if (data== "username can be used") {$ ("#username"). CSS ("Border-color", "green"); }else{$ ("#username"). CSS ("Border-color", "Red"); }}, Code alert ("Error in asynchronous request") executed after Error:function (ERROR,STATUS,XHR) {//failed); } }); }); */});</Script></Head><Body><formMethod= "POST"name= "F1"><TableAlign= "Center"><th>Please enter the registration information:</th><TR> <TD>User name:</TD> <TD><inputtype= "text"ID= "username"name= "username" /></TD><!--onblur= "Selectusername ()" -</TR><TR> <TD>Dense Code:</TD> <TD><inputtype= "Password"name= "Pass" /></TD></TR><TR> <TD>Confirm Password:</TD> <TD><inputtype= "Password"name= "Repass"/></TD></TR><TR> <TD>Nickname:</TD> <TD><inputtype= "text"name= "nickname" /></TD></TR><TR> <TD>Real name:</TD> <TD><inputtype= "text"name= "Realityname"/></TD></TR><TR> <TD><inputtype= "Submit"value= "Submit" /></TD> <TD><inputtype= "Reset"value= "Reset"/></TD></TR></Table></form></Body></HTML>
JQuery ajax-serialize () Method-Output serialized form values