快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://6mz.cn/article/iiiiec.html

其他资讯