• php,json数据传输(无刷新)


    废话不说直接上关键代码:

    js代码:

    <script language="javascript">
     
        $(".login").live('click',function(){        
            var username=$(".input_user").val();
            var password=$(".input_ps").val();    
            if(username==""){
                alert("用户名不能为空");
                return false;
            }
            if(password==""){
                alert("密码不能为空");
                return false;
            }
            var URL="checkLogin.php?";
            var DATA="&username="+username+"&password="+password;
            $.getJSON(URL+DATA,function(json){
                if(json.username=='true_u'&&json.password=='true_p'){
                    //alert(json.username+"|"+username+'...1');
                    window.location="index.php";
                }
                if(json.username=='error_u'||json.password=='error_p'){
                    alert("用户名输入或密码输入有误,请检查后重新登陆!");
                    window.location="login.php";
                }
                
            });
        });
    </script>

    checkLogin.php

    <?php
        include_once('connect.php');
        $username=$_GET['username'];
        $password=MD5($_GET['password']);
        //echo $username.'###'.$password;
        $sql="select * from admin";
        $result=mysql_query($sql);
        if(!$result){
            mysql_close();
            echo "登陆失败,请输入正确的用户名和密码!";
        }else{
            while($row=mysql_fetch_array($result)){
                if($row['username']==$username&&$row['password']==$password){
                    session_start();
                    $_SESSION['username']=$row['username'];
                    $adminInfo['username']='true_u';
                    $adminInfo['password']='true_p';                
                    mysql_close();
                }else 
                if($row['username']!=$username){
                    $adminInfo['username']='error_u';
                }
                if($row['password']!=$password){
                    $adminInfo['password']='error_p';
                }
                //var_dump($adminInfo);exit;
                echo json_encode($adminInfo);
            }
        }
    ?>

    其中主要被干倒的地方如下:

    在checkLogin.php最后,代码应该这么写:echo json_encode($adminInfo);

    之前写成:json_encode($adminInfo);结果打印 json.username老是undifined,以此为警戒....

  • 相关阅读:
    Rate Control Mode
    帝国的困境:80-20法则
    ARM NEON 64bit 查找表替换
    Video Brightness Enhancement
    HDR(High Dynamic Range)
    C++ C++
    Machine Learning
    图像处理
    Facial landmark detection
    git
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061404.html
Copyright © 2020-2023  润新知