中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

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

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

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

周口市| 肇庆市| 龙南县| 罗田县| 勐海县| 旬邑县| 东兰县| 治县。| 南汇区| 福泉市| 宜章县| 赣榆县| 滦南县| 定州市| 湖南省| 九寨沟县| 沈阳市| 福安市| 东阿县| 云浮市| 岗巴县| 囊谦县| 大姚县| 阳山县| 济阳县| 徐州市| 辉南县| 荃湾区| 华容县| 瑞安市| 科技| 会东县| 龙口市| 长子县| 祁连县| 耒阳市| 营口市| 靖西县| 新闻| 巴彦淖尔市| 清涧县|