zoukankan      html  css  js  c++  java
  • ajax接口测试代码,不依赖任何环境

    function ajax(url, method, data, f){
        var xhr;
        try{
            xhr=new XMLHttpRequest();
        }
        catch (e){
            try{
                xhr=new ActiveXObject('Msxml2.XMLHTTP');
            }
            catch (e){
                try{
                    xhr=new ActiveXObject('Microsoft.XMLHTTP');
                }
                catch (e){
                    alert("Don't support!");
                    return false;
                }
            }
        }
        xhr.onreadystatechange = f;
        xhr.open(method, url, false);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr.send(data);
    };
    
    ajax('/login.php', 'POST', 'username=username&password=password', function f(){
        if(this.readyState==4){
            if(this.status=200){
                eval('var obj=' + this.responseText + ';');
                alert(obj.success);
            }
            else{
                alert('Network interactive failure!');
            }
        }
    });
  • 相关阅读:
    JPA01
    mybatis入门
    PHP 循环- While循环
    PHP超级全局变量
    PHP 数组排序
    PHP数组
    PHP Switch语句
    PHP IF...Else语句
    PHP运算符
    PHP字符串变量
  • 原文地址:https://www.cnblogs.com/uniqid/p/5699252.html
Copyright © 2011-2022 走看看