zoukankan      html  css  js  c++  java
  • 16.PHP_Ajax模拟服务器登录验证

    Ajax模拟登陆验证

    index.php

    <script language="javascript">
        var http_request = false;

        function createRequest(url){
            http_request = false;
            if(window.XMLHttpRequest){                   //Mozilla、Safari等浏览器
                http_request = new XMLHttpRequest();
            }else if(window.ActiveXObject){              //IE
                try{
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
                }catch(e){
                    try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    }catch(e){}
                }
            }
            if(!http_request){
                alert("不能创建XMLHTTP实例!");
                return false;
            }
            http_request.onreadystatechange alertContents//指定相应方法
            //发出HTTP请求
            http_request.open("GET" ,url ,true);
            http_request.send(null);
        }

        function  alertContents() {
            if (http_request.readyState == 4) {//处理服务器返回的信息
                if (http_request.status == 200) {
                    alert(http_request.responseText);
                else {
                    alert("Ajax验证页面发生错误");
                }
            }
        }
    </script>

    <script language="javascript">
        function checkName(){
            var username = form1.name.value;
            if(username == ""){
                window.alert("name is null!");
                return false;
            }else {
                createRequest('checkname.php?username=' + username + '&nocache=' new Date().getTime());
            }
        }
    </script>

    <form name="form1" method="post" action="">
        <select name="name">
            <option value="xiaoming">xiaoming</option>
            <option value="xiaoli">xiaoli</option>
            <option value="xiaowang">xiaowang</option>
        </select>
        <input type="submit" name="Submit" value="Ajax" οnclick="checkName()">
    </form>



     

    CheckName.php

    <?php
        //模拟服务器验证
        $username $_GET['username'];
        echo 'Ajax Check web Get Name: '.$username;
    ?>

     

  • 相关阅读:
    遍历查询ldap服务器用户
    spring调用存储过程
    jms在jboss上的简单应用
    开发团队如何完成一个项目?
    数据库分区表的使用
    使用native 查询时,对特殊字符的处理。
    spring定时器分析
    sql server监控
    java 类和接口之间的转换
    C++ main 参数使用
  • 原文地址:https://www.cnblogs.com/csnd/p/12061972.html
Copyright © 2011-2022 走看看