#105 $.ajax change to fetch

master
Agriya Dev5 2021-06-01 14:57:11 +05:30
parent 51d817f7a9
commit e310b41020
1 changed files with 21 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/* eslint-disable max-len */ /* eslint-disable max-len */
/* globals seConfirm seAlert $ */ /* globals seConfirm seAlert */
/** /**
* The main module for the visual SVG this. * The main module for the visual SVG this.
* *
@ -1144,32 +1144,32 @@ class Editor extends EditorStartup {
loadFromURL(url, { cache, noAlert } = {}) { loadFromURL(url, { cache, noAlert } = {}) {
return this.ready(() => { return this.ready(() => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
$.ajax({ fetch (url, { cache: cache ? 'force-cache' : 'no-cache' })
url, .then( (response) =>
dataType: 'text', {
cache: Boolean(cache), if (!response.ok) {
beforeSend() { if (noAlert) {
$.process_cancel(this.i18next.t('notification.loadingImage')); reject(new Error('URLLoadFail'));
}, return;
success(str) { }
this.loadSvgString(str, { noAlert }); seAlert(this.i18next.t('notification.URLLoadFail') );
}, resolve();
error(xhr, stat, err) {
if (xhr.status !== 404 && xhr.responseText) {
this.loadSvgString(xhr.responseText, { noAlert });
return;
} }
return response.text();
})
.then( (str) =>
{
this.loadSvgString(str, { noAlert });
return str;
})
.catch( (error) => {
if (noAlert) { if (noAlert) {
reject(new Error('URLLoadFail')); reject(new Error('URLLoadFail'));
return; return;
} }
seAlert(this.i18next.t('notification.URLLoadFail') + ': \n' + err); seAlert(this.i18next.t('notification.URLLoadFail') + ': \n' + error);
resolve(); resolve();
}, });
complete() {
if ($id("dialog_box") != null) $id("dialog_box").style.display = 'none';
}
});
}); });
}); });
} }