Example of using form serialization and serialize in jq
This article mainly introduces the use of Form serialization and serialize in jq. For more information, see
The Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script type = "text/javascript" src = "lib/jquery-1.7.2.min.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("# BtnSubmit"). click (function (){
$. Ajax ({
Type: "post ",
Url: "Handler02.ashx ",
Data: $ ("# frmUserInfo"). serialize (),
Success: function (result ){
$ ("# Msg" cmd.html (result );
}
});
Return false;
});
});
</Script>
</Head>
<Body>
<Form id = "frmUserInfo" action = "#">
<Table>
<Tr>
<Td>
Name
</Td>
<Td>
<Input type = "text" id = "txtUserName" name = "txtUserName"/>
</Td>
</Tr>
<Tr>
<Td>
Password
</Td>
<Td>
<Input type = "password" id = "txtUserPwd" name = "txtUserPwd"/>
</Td>
</Tr>
<Tr>
<Td colspan = "2">
<Input type = "submit" id = "btnSubmit" value = "submit"/>
</Td>
</Tr>
</Table>
</Form>
<Div id = "msg"> </div>
</Body>
</Html>
Copy the Code as follows:
/// <Summary>
/// Handler Summary
/// </Summary>
Public class Handler02: IHttpHandler
{
/// <Summary>
/// Request processing
/// </Summary>
/// <Param name = "context"> </param>
Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
// Method 2 (corresponding to form serialization)
String userName = context. Request. Form ["txtUserName"]. ToString ();
String userPwd = context. Request. Form ["txtUserPwd"]. ToString ();
Context. Response. Write (string. Format ("Name: {0}, password: {1}", userName, userPwd ));
Context. Response. End ();
}
Public bool IsReusable
{
Get
{
Return false;
}
}
}