SOURCE

function request({url, method = 'get', params, headers}) {
    var xhr, data;
    var isGetMethod = method.toLocaleLowerCase() === 'get';
    var parseUrlParams = function(params = {}) {
        var result = ''
        for (i in params) {
            result += `${i}=${params[i]}&`
        }
        result = result.slice(0, result.length - 1);
        return result;
    };

    headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        ...headers,
    }

    if (window.ActiveXObject) {
        xhr = new ActiveXObject();
    } else {
        xhr = new XMLHttpRequest();
    }
    if (isGetMethod) {
        params = parseUrlParams(params);
        url = params ? `?${params}` : url;
        data = null;
    } else {
        data = JSON.stringify(params);
    }
    console.log(method, url, data)
    xhr.open(method, url, true);
    if (!isGetMethod) {
        for(i in headers) {
            xhr.setRequestHeader(i, headers[i]);
        }
    }
    xhr.send(data);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                console.log(`success:${xhr.responseText}`);
            } else {
                console.log(`fail:${xhr.status}`);
            }
        } 
    } 
}

// request({url:'http://localhost:8080/api/ambulance/anonymous/pic-verify-code'})
request({url: 'http://localhost:8080/api/ambulance/login', params: {
    "userName": "zlk002",
    "password": "482b80e14917dd713f719db73f99195d",
    "pictureCodeResult": "27",
    "pictureCodeUUID": "AmbulanceCode:d37e6206b45d41ada82b590cfb8f53d2",
    "rememberMe": true
}, method: 'post', headers: {
    'Content-Type' : 'application/json;charset=UTF-8'
}})
console 命令行工具 X clear

                    
>
console