Recently, in an application center, we need users to fill in data based on the pop-up layer results and then submit the data for ajax and there are multiple inputs. Next I will introduce the usage of $. the serialize () method and php implementation in ajax are described as follows.
Jquery code
| The Code is as follows: |
Copy code |
|
<Script language = "javascript">/* rebate process */
$ ('# Ajaxpassword'). click (function (){
// Alert ('bb ');
// Checkem ();
Var postData = $ ('# pwdmsg'). serialize ();
// Alert (postData );
$. Ajax ({
Type: "POST ",
Url: "update. php ",
Data: postData,
Success: function (msg ){
// Alert (msg );
If (msg = 1 ){
Alert ('password changed successfully. Please remember your new password! ');
Location. href = 'HTTP: // www. bKjia. c0m ';
} Else {
Alert (msg );
}
}
});
})
</Script>
Html |
<! -- Change Password -->
| The Code is as follows: |
Copy code |
|
<Div id = "passworddiv">
<Form id = "pwdmsg" name = "pwdmsg">
<Div class = "aui_outer">
<Table class = "aui_border">
<Tr>
<Td class = "aui_nw"> </td>
<Td class = "aui_n"> </td>
<Td class = "aui_ne"> </td>
</Tr>
<Tr>
<Td class = "aui_w"> </td>
<Td class = "aui_c">
<Div class = "aui_inner">
<Div class = "close_lay"> <a href = "javascript: closela ('passworddiv ');"> </a> </div>
<Div class = "aui_title"> Change Password </div>
<Div class = "aui_content">
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<Td class = "td_1"> old logon password: </td>
<Td> <input name = "oldpwd" class = "text text_w2" type = "password" id = "oldpwd"> </td>
</Tr>
<Tr>
<Td class = "td_1"> New logon password: </td>
<Td> <input name = "newpwd" type = "password" class = "text text_w2" id = "newpwd" size = "30"> & nbsp; the password consists of 6 to 12 characters </td>
</Tr>
<Tr>
<Td class = "td_1"> confirm the new password: </td>
<Td> <input name = "newpwd1" type = "password" class = "text text_w2" id = "newpwd1" size = "30"> </td>
</Tr>
</Table>
</Div>
<Div class = "aui_jtqx"> <input type = "button" name = "" value = "Save Password" class = "aui_tjbtn" id = "ajaxpassword"/>
<Input name = "action" type = "hidden" value = "6">
</Div>
</Div> </td>
<Td class = "aui_e"> </td>
</Tr>
<Tr>
<Td class = "aui_sw"> </td>
<Td class = "aui_s"> </td>
<Td class = "aui_se" style = "cursor: se-resize;"> </td>
</Tr>
</Table>
</Div>
</Form>
</Div> |
Update. php
This file is updated after receiving ajax data in post mode. Note: ajax encoding is uft8. If you are a gbk page, we can convert the character encoding.