mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-03-22 01:44:11 -05:00
- Moved the web-api to the master branch
- Rewrote parts of the web-api to support ES6
- Added local webserver to the web-api
- Added command to start the local webserver ("npm run api")
22 lines
669 B
JavaScript
22 lines
669 B
JavaScript
function send(data, resolve) {
|
|
const xhr = new XMLHttpRequest();
|
|
const protocol = window.location.protocol;
|
|
xhr.open("POST", `${protocol}//${CFG.API.HOST}:${CFG.API.PORT}${CFG.API.ROUTE}`, true);
|
|
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
xhr.onreadystatechange = () => {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.status === 200) {
|
|
if (typeof resolve === "function") {
|
|
try {
|
|
resolve(JSON.parse(xhr.responseText));
|
|
} catch (e) {
|
|
resolve(void 0);
|
|
}
|
|
}
|
|
} else {
|
|
resolve(xhr.statusText);
|
|
}
|
|
}
|
|
};
|
|
xhr.send(JSON.stringify(data));
|
|
} |