Commit aa24e641 authored by liujiangnan's avatar liujiangnan

feat

parent dcc1d80c
import { initAir } from './air';
cc.Class({
extends: cc.Component,
properties: {
......@@ -9,7 +9,7 @@ cc.Class({
if (!baseUrl) {
baseUrl = await this.getBaseUrl();
}
await (new Promise((resolve, reject) => {
const resData = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const url = `${baseUrl}${uri}`;
xhr.open("POST", url, true);
......@@ -17,19 +17,18 @@ cc.Class({
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
resolve(JSON.parse(xhr.responseText));
} else {
reject(xhr.responseText);
}
}
xhr.send(JSON.stringify(data));
}));
});
return resData;
},
async callNetworkApiGet(uri, data, baseUrl = null) {
if (!baseUrl) {
baseUrl = await this.getBaseUrl();
}
await (new Promise((resolve, reject) => {
const resData = await new Promise((resolve, reject) => {
let queryStr = '?';
const params = [];
for (const key in data) {
......@@ -42,15 +41,14 @@ cc.Class({
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
resolve(JSON.parse(xhr.responseText));
} else {
reject(xhr.responseText);
}
};
const url = `${baseUrl}${uri}${queryStr}`;
console.warn('url = ' + url);
xhr.open('GET', url, true);
xhr.send();
}));
});
return resData;
},
async getBaseUrl() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment