Use fetch instead of jquery get

This commit is contained in:
Gabriel Augendre 2021-06-22 12:20:25 +02:00
parent 212889e9a1
commit f133c182f9

View file

@ -44,16 +44,12 @@ document.addEventListener("DOMContentLoaded", function (event) {
} }
disableFields(); disableFields();
$.get("/isbn_api/" + isbn.value, {}, function (data, status, xhr) { fetch("/isbn_api/" + isbn.value).then(function (data) {
if (data.error) { if (!data.ok) {
isbn.classList.add('is-invalid'); throw Error("Erreur dans la récupération des données");
isbn.classList.remove('is-valid');
feedback.style.display = 'block';
feedback.textContent = data.error;
enableFields();
return;
} }
return data.json();
}).then(function (data) {
isbn.classList.remove('is-invalid'); isbn.classList.remove('is-invalid');
isbn.classList.add('is-valid'); isbn.classList.add('is-valid');
feedback.style.display = 'none'; feedback.style.display = 'none';
@ -97,6 +93,12 @@ document.addEventListener("DOMContentLoaded", function (event) {
event.initEvent("change", true, true); event.initEvent("change", true, true);
event.eventName = "change"; event.eventName = "change";
document.querySelector('#id_editor').dispatchEvent(event); document.querySelector('#id_editor').dispatchEvent(event);
}).catch(function(error) {
isbn.classList.add('is-invalid');
isbn.classList.remove('is-valid');
feedback.style.display = 'block';
feedback.textContent = error;
enableFields();
}); });
}); });
}); });