0
0
mirror of https://github.com/Doodle3D/Doodle3D-API synced 2024-12-22 13:53:48 +01:00

use one function for ajax calls

This commit is contained in:
casperlamboo 2016-04-18 10:19:51 +02:00
parent 730d015435
commit da7245218b

View File

@ -8,32 +8,19 @@ const POST_TIMEOUT = 10000;
const queue = [];
export function get (url) {
return new Promise((resolve, reject) => {
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
timeout: GET_TIMEOUT,
success: (response) => {
if (response.status === 'success') {
resolve(response.data, response.msg);
}
else {
reject(response.msg);
}
}
}).fail(reject);
});
return await ajax(url, 'GET');
}
export function post (url, data) {
return await ajax(url, 'POST', data);
}
function ajax(url, type, data) {
const timeout = (type === 'GET') ? GET_TIMEOUT : POST_TIMEOUT;
return new Promise((resolve, reject) => {
$.ajax({
url: url,
type: 'POST',
data: data,
dataType: 'json',
timeout: POST_TIMEOUT,
url, type, data, timeout, dataType: 'json',
success: (response) => {
if (response.status === 'success') {
resolve(response.data);