| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- const getRootPath = () => {
- const protocol = window.location.protocol;
- const host = window.location.host;
- const localhostPath = protocol + '//' + host;
- return 'http://192.168.1.106:8083';
- // return localhostPath;
- }
- // 获取API的地址
- const getApiURL = (apiName) => {
- return getRootPath() + 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',
- 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);
- },
- });
- });
- }
|