const baseURL = "http://192.168.10.102:9008"; const imageURL = "http://192.168.10.102:9011/"; // const baseURL = "http://175.27.168.120:6019"; // const imageURL = "http://175.27.168.120:6023/"; const timeout = 3000; // requet ajax function request(url, method, data = {}, contentType, back) { $.ajax({ url: baseURL + url, type: method, cache: false, timeout: timeout, contentType: contentType, headers: { "X-Token": localStorage.getItem("token") || "", }, dataType: "json", data: JSON.stringify(data), success: function (res) { return typeof back == "function" && back(res); }, error: function (error) { console.log(error); if (error.responseJSON && error.responseJSON.code == 401) { toastr.error("登录信息已过期,请重新登录"); localStorage.removeItem("token"); window.location.href = "login.html"; return false; } else { return typeof back == "function" && back(null); } }, }); } function getAjaxRequst(url, _data, callBack) { request(url, "GET", _data, "application/json", function (res) { if (res && res.code == 200) { return typeof callBack == "function" && callBack(res); } else { toastr.error("网络错误"); } }); } function postAjaxRequst(url, _data, callBack) { request(url, "POST", _data, "application/json", function (res) { return typeof callBack == "function" && callBack(res); }); } function uploadFile(url, data, callBack) { $.ajax({ url: imageURL + url, data: data, method: "POST", processData: false, contentType: false, success: function (data) { return typeof callBack == "function" && callBack(data); }, error: function (error) { console.log(error); return typeof callBack == "function" && callBack(null); }, }); }