You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
680 B
33 lines
680 B
import $ from 'jquery';
|
|
|
|
export default function createAjaxRequest() {
|
|
return function(ajaxOptions) {
|
|
const requestXHR = new window.XMLHttpRequest();
|
|
let aborted = false;
|
|
let complete = false;
|
|
|
|
function abortRequest() {
|
|
if (!complete) {
|
|
aborted = true;
|
|
requestXHR.abort();
|
|
}
|
|
}
|
|
|
|
const request = $.ajax({
|
|
xhr: () => requestXHR,
|
|
...ajaxOptions
|
|
}).then(null, (xhr, textStatus, errorThrown) => {
|
|
xhr.aborted = aborted;
|
|
|
|
return $.Deferred().reject(xhr, textStatus, errorThrown).promise();
|
|
}).always(() => {
|
|
complete = true;
|
|
});
|
|
|
|
return {
|
|
request,
|
|
abortRequest
|
|
};
|
|
};
|
|
}
|