Enh #3907: Allow client.ajax().abort()

This commit is contained in:
buddh4 2020-03-10 16:24:18 +01:00
parent 28e1fdf337
commit 8c3b01fcf5

View File

@ -207,6 +207,8 @@ humhub.module('client', function (module, require, $) {
cfg = {'success': cfg};
}
var requestXhr = null;
var promise = new Promise(function (resolve, reject) {
cfg = cfg || {};
@ -255,9 +257,19 @@ humhub.module('client', function (module, require, $) {
});
};
var beforeSendHandler = cfg.beforeSend;
var beforeSend = function (xhr, settings) {
if(beforeSendHandler) {
beforeSendHandler(xhr, settings);
}
requestXhr = xhr;
};
//Overwriting the handler with our wrapper handler
cfg.success = success;
cfg.error = error;
cfg.beforeSend = beforeSend;
cfg.url = url;
$.ajax(cfg);
@ -289,6 +301,12 @@ humhub.module('client', function (module, require, $) {
});
};
promise.abort = function() {
if(requestXhr) {
requestXhr.abort();
}
};
return promise;
};