Ajax no-refresh form submission

Source: Internet
Author: User
Tags dsn

Ajax No Refresh Submit notes

The database builds a self-simulation to execute the Add function

The PHP section uses the PDO method:

<?php$db = ' MySQL '; $host = ' localhost '; $port = ' 3306 '; $dbname = ' ajax '; $user = ' root '; $pwd = '; $dsn = "$db: host= $host;p o   rt= $port;d bname= $dbname "; Sets the character Set $options = Array (pdo::mysql_attr_init_command=> ' Set NAMES \ ' utf8\ '); $pdo = new PDO ($DSN, $user, $pwd, $options); $name = $_post[' name '];//print_r ($name); exit; $pwd = $_post[' pwd ']; $code = $_po st[' code '; $sql = "INSERT into user (Name,pwd,code) VALUES ('". $name. "', '". $pwd. "', '". $code. "')";  $res = $pdo->exec ($sql);   if ($res) {echo 1; Exit;}   else{Echo 2; Exit;}

Ajax Frontend Part

<script type= "Text/javascript"  src= "Jquery-1.8.3.min.js" ></script>         <script type= "Text/javascript" >         $ (function () {            $ (". User_main _r button "). Click (function () {                                     $.post ('./login.php ',  $ (' form '). Serialize (),  function (data)  {                                  if (data == 1) {                     alert  (' Add success ');                      $ ("#admin_user"). Val (');                      $ ("#admin_psd"). Val (');                      $ ("#captcha"). Val (');                 }else{                     alert  (' Add failed ');                 }                               });                          });                 });                                            </script>        <title> No Refresh User Login </title>    


This article from "Kangjunfei" blog, reproduced please contact the author!

Ajax no-refresh form submission

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.