• 登录


    <--HTML代码!->
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>登录</title>
    </head>
    <body>
    <label>用户名</label>
    <input type="text" id="username"><br>
    <label>密码</label>
    <input type="password" id="password"><br>
    <button value="button" id="btn">登录</button>
    <div id="result"></div>
    <script>
    window.onload = function(){
    document.getElementById('btn').onclick = function(){
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    //兼容浏览器 初始化
    var xhr;
    if(window.XMLHttpRequest){
    xhr = new XMLHttpRequest();
    }else{
    xhr = new ActiveXObject("Microsoft.XMLHttP")
    }
    //准备好了
    var url = "demo/03Login.php?username=" + username + "&password=" + password;
    xhr.open("get",url);
    xhr.send();
    //开始监听获取到的数据
    xhr.onreadystatechange = function(){
    if(xhr.readyState === 4 && xhr.status === 200){
    //alert(xhr.responseText);
    if( xhr.responseText == 2){
    document.getElementById("result").innerHTML = "登录成功";
    }else if(xhr.responseText == 1){
    document.getElementById("result").innerHTML = "登录名或密码错误";
    }
    }
    };
    }
    }

    </script>
    </body>
    </html>

    <--php代码-->

    <?php
    header("Content-type: text/html; charset=utf-8");
    $username = $_GET['username'];
    $password = $_GET['password'];
    if($username === "admin" && $password === "123"){
    echo 2;

    }else{
    echo 1;
    }

    ?>




  • 相关阅读:
    20170416
    汇总02
    总结
    在编程的世界中,如何高效地学习理论知识,应用理论知识来解决实际生产中的问题
    周末待整理
    web 性能提升
    es6
    http、https、 json、 ajax
    微信小程序 问题收集
    eslint
  • 原文地址:https://www.cnblogs.com/zhaocong/p/8610603.html
Copyright © 2020-2023  润新知