PanDuWeb/js/request.js

38 lines
1.0 KiB
JavaScript

const baseURL = "http://192.168.10.102:9008";
const imageURL = "http://175.27.168.120:6023/";
const timeout = 3000;
// requet ajax
function request(url, method, data = {}, contentType, back) {
console.log("data::: ", data);
$.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);
return typeof back == "function" && back(null);
},
});
}
function getAjaxRequst(url, _data, callBack) {
request(url, "GET", _data, "application/json", function (res) {
return typeof callBack == "function" && callBack(res);
});
}
function postAjaxRequst(url, _data, callBack) {
request(url, "POST", _data, "application/json", function (res) {
return typeof callBack == "function" && callBack(res);
});
}