mirror of
https://github.com/Doodle3D/Doodle3D-API
synced 2025-01-03 10:03:48 +01:00
use one function for ajax calls
This commit is contained in:
parent
730d015435
commit
da7245218b
@ -8,32 +8,19 @@ const POST_TIMEOUT = 10000;
|
|||||||
const queue = [];
|
const queue = [];
|
||||||
|
|
||||||
export function get (url) {
|
export function get (url) {
|
||||||
return new Promise((resolve, reject) => {
|
return await ajax(url, 'GET');
|
||||||
$.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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function post (url, data) {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url, type, data, timeout, dataType: 'json',
|
||||||
type: 'POST',
|
|
||||||
data: data,
|
|
||||||
dataType: 'json',
|
|
||||||
timeout: POST_TIMEOUT,
|
|
||||||
success: (response) => {
|
success: (response) => {
|
||||||
if (response.status === 'success') {
|
if (response.status === 'success') {
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
|
Loading…
Reference in New Issue
Block a user