mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-22 05:15:29 +09:00
WIP
This commit is contained in:
parent
dc21fc3007
commit
82feb232f6
1 changed files with 29 additions and 32 deletions
|
|
@ -464,36 +464,33 @@ Rhymix.ajax = function(action, params, success, error) {
|
||||||
headers: headers,
|
headers: headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Split between Promise version and callback version
|
return new Promise(function(resolve, reject) {
|
||||||
if ($.isFunction(success) || $.isFunction(error)) {
|
const resolveWrapper = function(data, xhr) {
|
||||||
try {
|
if (typeof success === 'function') {
|
||||||
$.ajax($.extend(args, {
|
success(data, xhr);
|
||||||
success: function(data, textStatus, xhr) {
|
}
|
||||||
Rhymix._ajaxSuccessHandler(xhr, textStatus, action, data, params, success, error);
|
if (resolve) {
|
||||||
},
|
resolve(data);
|
||||||
error: function(xhr, textStatus, errorThrown) {
|
}
|
||||||
Rhymix._ajaxErrorHandler(xhr, textStatus, action, url, params, success, error);
|
};
|
||||||
}
|
const rejectWrapper = function(data, xhr) {
|
||||||
}));
|
if (typeof error === 'function' && error(data, xhr) === false) {
|
||||||
} catch(e) {
|
|
||||||
alert(e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
const rejectWrapper = function(data, xhr) {
|
|
||||||
reject(data, xhr);
|
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
$.ajax($.extend(args, {
|
if (reject) {
|
||||||
success: function(data, textStatus, xhr) {
|
reject(data);
|
||||||
Rhymix._ajaxSuccessHandler(xhr, textStatus, action, data, params, resolve, rejectWrapper);
|
return false;
|
||||||
},
|
}
|
||||||
error: function(xhr, textStatus, errorThrown) {
|
};
|
||||||
Rhymix._ajaxErrorHandler(xhr, textStatus, action, url, params, resolve, rejectWrapper);
|
$.ajax($.extend(args, {
|
||||||
}
|
success: function(data, textStatus, xhr) {
|
||||||
}));
|
Rhymix._ajaxSuccessHandler(xhr, textStatus, action, data, params, resolveWrapper, rejectWrapper);
|
||||||
});
|
},
|
||||||
}
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
|
Rhymix._ajaxErrorHandler(xhr, textStatus, action, url, params, resolveWrapper, rejectWrapper);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -524,7 +521,7 @@ Rhymix._ajaxSuccessHandler = function(xhr, textStatus, action, data, params, suc
|
||||||
if (typeof data.error !== 'undefined' && data.error != 0) {
|
if (typeof data.error !== 'undefined' && data.error != 0) {
|
||||||
|
|
||||||
// If an error callback is defined, call it. Abort if it returns false.
|
// If an error callback is defined, call it. Abort if it returns false.
|
||||||
if ($.isFunction(error) && error(data, xhr) === false) {
|
if (typeof error === 'function' && error(data, xhr) === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -551,7 +548,7 @@ Rhymix._ajaxSuccessHandler = function(xhr, textStatus, action, data, params, suc
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a success callback was defined, call it.
|
// If a success callback was defined, call it.
|
||||||
if ($.isFunction(success)) {
|
if (typeof success === 'function') {
|
||||||
success(data, xhr);
|
success(data, xhr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -595,7 +592,7 @@ Rhymix._ajaxErrorHandler = function(xhr, textStatus, action, url, params, succes
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an error callback is defined, call it. Abort if it returns false.
|
// If an error callback is defined, call it. Abort if it returns false.
|
||||||
if ($.isFunction(error)) {
|
if (typeof error === 'function') {
|
||||||
let fakedata = { error: -3, message: textStatus };
|
let fakedata = { error: -3, message: textStatus };
|
||||||
if (error(fakedata, xhr) === false) {
|
if (error(fakedata, xhr) === false) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue