From e310b41020fe2487b73f84d2f1d9bb18c3778ac1 Mon Sep 17 00:00:00 2001 From: Agriya Dev5 Date: Tue, 1 Jun 2021 14:57:11 +0530 Subject: [PATCH] #105 $.ajax change to fetch --- src/editor/Editor.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index b8a7420b..39f4afbc 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -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'; - } - }); + }); }); }); }