/*舒工AJAX-lite 1.0 -- 最精简的ajax自定义访问方法/
if ($g) {
$g.$utils || ($g.$utils = {});
} else {
var $g = {};
$g.$utils = {};
}
$g.$utils.ajax = o => {
var p = o.post, g = o.get, d = p.data, a = p.async, J = "json", j = p[J], s = g.success, e = g.error;
d = {
async: a == undefined || a, / false(解决手机端同步多次请求接口报错的问题)/ timeout: 60000, type: p.type || "post", url: p.url, data: d, success(r) {
s && s(r);
}, error(r) {
e && e(r);
}
};
d.data || delete d.data;
(d.data && Object.keys(d.data).length === 0) && delete d.data;
j === false ? (d.dataType = J) : (d.data = JSON.stringify(d.data), d.contentType = "application/" + J) , $.ajax(d);
};
/*调用舒工AJAX-lite 1.0/
$g.$utils.ajax({
post: {type:'post',url: "http://your_api",data:{key:value}},
get: {
success(d) {/ loading.close();//停止加载/
if (d.code == 200) {
console.log(d);
} else {
alert(JSON.stringify(d, null, 4));
}
}, error(d) {
console.log("【报错】" + JSON.stringify(d, null, 4));
},
}
});
因此衍生出sgData.js可以封装好所有的存取数据的接口