91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ajax無刷新表單提交

發布時間:2020-07-20 13:35:06 來源:網絡 閱讀:453 作者:kangjunfei 欄目:web開發

ajax無刷新提交筆記

數據庫自己模擬建一個 執行一下添加功能

php部分采用pdo方法:

<?php
$db ='mysql';
$host ='localhost';
$port ='3306';
$dbname = 'ajax';
$user = 'root';
$pwd  = '';

$dsn = "$db:host=$host;port=$port;dbname=$dbname";  

 //設定字符集 
$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  = $_POST['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前端部分

<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 ('添加成功');
                     $("#admin_user").val('');
                     $("#admin_psd").val('');
                     $("#captcha").val('');
                }else{
                   alert ('添加失敗');
                }      
            
            });
            
            });
        
        });

               
         
         
        </script>

        <title>無刷新用戶登錄</title>

    </head>
    <body id="userlogin_body">
     

                    <form id="form" method="post" >
                        <ul>
                     
                                <div class="user_main_box">
                                    <ul>
                                        <li class="user_main_text">用戶名: </li>
                                        <li class="user_main_input">
                                            <input id="admin_user" name="name" maxlength="20" /> 
                                            
                                   </li>
                                   </ul>

                                    <ul>
                                        <li class="user_main_text">密&nbsp;&nbsp;&nbsp;&nbsp;碼: </li>
                                        <li class="user_main_input">
                                            <input class="TxtPasswordCssClass" id="admin_psd" name="pwd" type="password">
                                            
                                        </li>
                                    </ul>
                                    <ul>
                                        <li class="user_main_text">×××: </li>
                                        <li class="user_main_input">
                                            <input class="TxtValidateCodeCssClass" id="captcha" name="code" type="text">
                                                                       
                                        </li>
                                    </ul>
                                    
                                </div>
                            </li>
                            <li class="user_main_r">

                                <button  type="button" >提交</button>
                            </li>
                        </ul>
                    </form>
           
    </body>


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

革吉县| 吐鲁番市| 上蔡县| 库车县| 墨玉县| 莱州市| 黑龙江省| 清水河县| 如皋市| 剑阁县| 勃利县| 新津县| 永清县| 浮梁县| 青铜峡市| 龙泉市| 古田县| 南陵县| 临沧市| 绵竹市| 台安县| 元氏县| 信丰县| 宽甸| 上思县| 高雄市| 三原县| 广汉市| 富源县| 延寿县| 陇川县| 嘉义市| 阿城市| 鹤山市| 陵水| 荆门市| 米泉市| 星子县| 镇康县| 承德市| 阳春市|