JQuery ajax-serialize () Method-Output serialized form values

Source: Internet
Author: User

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&nbsp;&nbsp;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.