ajax无刷新表单提交

ajax无刷新提交笔记

创新互联是一家集网站建设,通河企业网站建设,通河品牌网站建设,网站定制,通河网站建设报价,网络营销,网络优化,通河网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

数据库自己模拟建一个 执行一下添加功能

php部分采用pdo方法:

'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前端部分


        
        $(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 ('添加失败');
                }      
            
            });
            
            });
        
        });

               
         
         
        

        无刷新用户登录

    
    
     

                    
                        
                                                                                               
                                              用户名:                                                                                                                                                                                                             
                                        
                                              密    码:                                                                                                                                                                                                                  
                                        
                                              ×××:                                                                                                                                                                                                                                             
                                                                         
                                                                                          提交                                                                                            
网站标题:ajax无刷新表单提交
本文来源:http://azwzsj.com/article/iiiiec.html

其他资讯