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