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