zoukankan      html  css  js  c++  java
  • 原生js实现ajax用于简单的签到或登录

    <script>
    function createStandardXHR() {
        try {
            return new window.XMLHttpRequest();
        } catch( e ) {}
    }
    function createActiveXHR() {
        try {
            return new window.ActiveXObject( "Microsoft.XMLHTTP" );
        } catch( e ) {}
    }
    function getXhr() {
        var xhr = window.ActiveXObject !== undefined ?
        // Support: IE6+
        function() {
            return createStandardXHR() || createActiveXHR();
        } :
        // For all other browsers, use the standard XMLHttpRequest object
        createStandardXHR;
        return xhr;
    }
    function get(url, callback){ 
        var req = getXhr()();
        if(req){ 
            req.open("GET", url, true); 
            req.onreadystatechange = function(){ 
                if(req.readyState == 4){ 
                    if(req.status == 200){ 
                        callback(req.responseText);
                    }else{ 
                        alert("error"); 
                    } 
                } 
            } 
            req.send(null); 
        } 
    }
        !(function(win, document){
            var ipt_email = document.getElementById('ipt_email');
            ipt_email.onfocus = function(){
                this.value = '';
            };
            var ipt_sub = document.getElementById('ipt_sub');
            var tot_email = document.getElementById('tot_email');
            ipt_sub.onclick = function(){
                var val = ipt_email.value;
                if(/w/.test(val)){
                    var url = 'index.php?email_prefix=' + val;
                    get(url,function(data){
                        if ('1' === data) {
                            alert('签到成功!欢迎出席搜房十六周年庆典暨扩大管理会议!');
                        } else if ('2' === data) {
                            alert('对不起,您已经签到过!');
                        } else if ('3' === data) {
                            alert("对不起,还未到签到时间,请耐心等待!");
                        } else {
                            alert('对不起,未能匹配到您的信息,请核对邮箱!');
                        }
                    });
                }else{
                    tot_email.getElementsByTagName('p')[0].innerHTML = '请正确输入邮箱地址!';
                }
            };
        })(window, document)
        </script>

    访问地址 http://m.fang.com/public/qd/

  • 相关阅读:
    什么时候用GET?什么时候用POST?
    Oracle存储过程in、out、in out 模式参数
    oracle的spool功能
    xshell-常用命令
    js Date()日期函数浏览器兼容问题解决方法
    spring-quartz
    spring-quartz普通任务与可传参任务
    MySQL服务安装和可视化工具安装
    PL/SQL Developer 查询的数据有乱码或者where 字段名=字段值 查不出来数据
    Windows下安装Redis服务
  • 原文地址:https://www.cnblogs.com/ryanlamp/p/4746756.html
Copyright © 2011-2022 走看看