Use jquery ajax serialize to save data without refreshing the instance

Source: Internet
Author: User

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.

Related Article

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.