axios封装, 原生xhr ajax同步请求 封装
(function (_window) {
const axiosUtil = {
};
/**
* get请求 异步
* 参数可以通过mapping 中 增加? a=1&b=2 传递
* 也可以通过reqData.param传递,会解析json对象拼接到url后面
* reqData.param={
* a:1,
* b:2
* }
* @param
* reqData {
* "mapping":"",
* "callback":function(){},
* "scope":this
* }
*/
axiosUtil.get = function (reqData) {
let mapping = reqData.mapping;
let callback = reqData.callback;
// let scope=reqData.scope;
if (myApp.devModel) {
console.log("get ajax begin reqData:" + JSON.stringify(reqData));
}
let url = myApp.getUrl() + mapping;
if (url.indexOf("?") > 0) {
url += "×tamp=" + new Date().getTime();
} else {
url += "?timestamp=" + new Date().getTime();
}
for(let paramKey in reqData.param){
url+="&"+paramKey+"="+reqData.param[paramKey];
}
axios.get(url).then(response => {
// console.log(response);
let resData = response.data;
if (myApp.devModel) {
console.log("get ajax end resData:" + JSON.stringify(resData));
}
callback(resData);
})
.catch(function (error) {
console.log(error