SOURCE

function ajax(options) {
    const xhr = new XMLHttpRequest();

    options = options || {};
    options.type = (options.type || "GET").toUpperCase();
    options.dataType = options.dataType || "json";
    const params = options.data;

    if (options.type == "GET") {
        xhr.open("GET", options.url + '?' + params, true);
        xhr.send(null)
    }else if(options.type == "POST") {
        xhr.open("OPEN", options.url);
        xhr.send(params)
    }

    xhr.onreadystatechange = function() {
        if(xhr.readyState === 4) {
            if(xhr.status >= 200 && xhr.status <= 300) {
                options.success && options.success(xhr.responseText, xhr.responseXML)
            }else if (xhr.status >= 400) {
                options.fail && options.fail(xhr.status)
            }
        }
    }
}

ajax({
    type: "POST",
    dataType: "json",
    data:{},
    url: '10.0.1.5',
    success: function (text, xml) {
        console.log(text)
    },
    fail: function(status) {
        console.log(status)
    }
})
console 命令行工具 X clear

                    
>
console