function ajax(options) { let defaults = { type: "get" } Object.assign(defaults, options) let xhr = null if (window.VBArray) { xhr = new ActiveXObject("Msxml2.XMLHTTP") } else { xhr = new XMLHttpRequest() } xhr.open(defaults.type, defaults.url) xhr.onload = function () { defaults.success ? defaults.success(JSON.parse(xhr.response)) : "" } if (defaults.type == "get") { xhr.send() } if (defaults.type == "post") { xhr.setRequestHeader("content-Type", "application/x-www-from-urlencoded") xhr.send(defaults.data) } }
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄