自定义请求
/**
* 自定义请求
* @param option{method,url,async,contentType,data,success}
*/
function httpClient(option){
option.method = option.method !== undefined ? option.method : "POST"
option.async = option.async !== undefined ? option.async : false
option.contentType = option.contentType !== undefined ? option.contentType : "application/json"
option.data = option.data !== undefined ? option.data : {}
option.success = option.success !== undefined ? option.success : function (result){}
const xhr = new XMLHttpRequest();
xhr.open(option.method, option.url, option.async);
xhr.setRequestHeader("Content-type", option.contentType);
xhr.onload = function (){
if (xhr.readyState === 4 && xhr.status === 200) {
option.success(JSON.parse(xhr.response))
}
}
xhr.send(JSON.stringify(option.data));
}