A simple example of jquery ajax serialize submitting and saving data

Source: Internet
Author: User
Tags php code

Html code

The code is as follows: Copy code

<Table width = "100%" border = "0" cellspacing = "1" cellpadding = "1" style = "margin-top: 20px;">
<Form id = "submitform" name = "submitform">
<Tr>
<Td height = "40" class = "align_c"> Customer Information: </td>
<Td> Name: <? = Iconv ('gbk', 'utf-8', $ rs ['buy _ name']);?>, Mobile phone: <? = $ Rs ['buy _ Tel'];?> </Td>
</Tr>
<Tr>
<Td height = "40" class = "align_c"> customer name: </td>
<Td> <label for = "textfield"> </label>
<Input type = "text" name = "c_name" id = "c_name" value = "<? = Iconv ('gbk', 'utf-8', $ rs ['buy _ name']);?> "/> </Td>
</Tr>
<Tr>
<Td height = "40" class = "align_c"> customer's phone number: </td>
<Td> <input type = "text" name = "c_tel" id = "c_tel" value = "<? = $ Rs ['buy _ Tel'];?> "/> </Td>
</Tr>
<Tr>
<Td height = "40" class = "align_c"> customer gender: </td>
<Td>
<Select name = "c_sex" id = "c_sex">
<Option value = "0"> Female </option>
<Option value = "1"> male </option>
<Option value = "2"> Unknown </option>
</Select>
</Td>
</Tr>
 
<Tr>
<Td width = "14%" height = "40" class = "align_c"> enter the broker ID: </td>
& Lt; td width = "86%" & gt;
<Div class = "login">
<Input type = "text" maxlength = "128" name = "title" id = "title" placeholder = "Enter the broker id" onkeyup = "getreNews (this. value); "autocomplete =" off "/>
<Input name = "agid" type = "hidden" id = "agid"/>
<Input name = "id" type = "hidden" value = "<? = $ Mid;?> "/>
<Ul id = "apDiv1" style = "position: absolute; left: 0px; top: 24px">
                          
</Ul>
</Div>
<Span class = "liru"> Example: 138 </span>
</Td>
</Tr>
<Tr>
<Td height = "40"> & nbsp; </td>
<Td>
<Input name = "button" type = "button" class = "button_style" id = "ajaxsubmit" value = "start transfer"/>
</Td>
</Tr> </form>
</Table>
<Script language = "javascript">


$ ('# Ajaxsubmit'). click (function (){
Var agid = $ ("# agid"). val ();
If (agid = '')
 {
Alert ('select the ID number of the broker to be transferred first! '); Return false;
 }
 
Var postData = $ ('# submitform'). serialize ();
// Alert (postData );
$. Ajax ({
Type: "POST ",
Url: "ajaxSave. php ",
Data: postData,
Success: function (msg ){
If (msg = 0 ){
Alert ('forwarding successful. You can check the status of this customer at any time! ');
   }
Else if (msg =-2)
   {
Alert ('The user has been transferred successfully. Please do not submit it again! ');
   }
Else
   {
Alert ('sorry, the system is busy. Please try again later! '+ Msg );
   }
  }
});
})
</Script>

In the previous section, the efficiency improvement data is saved to the database by ajaxSave. php. Let's take a look at the ajaxSave. php file.

The code is as follows: Copy code

$ SQL = "insert into abctage (B _name,) value (4 )";

$ Query = $ Db-> query ($ SQL) or die (mysql_error ());
If ($ query)
{
Cho 0;
}
Else
{
Echo-1;
}

I simplified the above php code for loading data into the database. You can operate it according to your own situation.

This site Original tutorial conversion indicated Source http://www.111cn.net

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.