| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- const getRootPath = () => {
- const protocol = window.location.protocol;
- const host = window.location.host;
- const localhostPath = protocol + '//' + host;
- // return 'http://192.168.1.6:10026';
- return localhostPath;
- }
- // 获取API的地址
- const getApiURL = (apiName) => {
- return getRootPath() + apiName;
- // return 'http://192.168.1.112:10026' + apiName;
- }
- const ajaxGet = (url, data) => {
- let requestUrl = url
- let paramCount = 0;
- if (data) {
- data.forEach(item => {
- requestUrl += (paramCount > 0) ? '&' : '?';
- requestUrl += (`${item[0]}` + `=${item[1]}`);
- paramCount++;
- })
- }
- return new Promise((resolve, reject) => {
- $.ajax({
- url: getApiURL(requestUrl),
- type: 'get',
- contentType: 'application/json',
- beforeSend: function (request) {
- request.setRequestHeader('token', localStorage.getItem('#token'));
- },
- success: function (data) {
- resolve(data);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- reject(XMLHttpRequest);
- },
- });
- });
- }
- const ajaxPost = (url, params) => {
- return new Promise((resolve, reject) => {
- $.ajax({
- url: getApiURL(url),
- type: 'post',
- contentType: 'application/json',
- data: JSON.stringify(params),
- success: function (data) {
- resolve(data);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- reject(XMLHttpRequest);
- },
- });
- });
- }
|