Use fetch instead of jquery get
This commit is contained in:
parent
212889e9a1
commit
f133c182f9
1 changed files with 12 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
||||||
document.addEventListener("DOMContentLoaded", function (event) {
|
document.addEventListener("DOMContentLoaded", function (event) {
|
||||||
$(function () {
|
$(function () {
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
});
|
});
|
||||||
|
|
||||||
var isbnButton = document.querySelector('#id_isbn_button');
|
var isbnButton = document.querySelector('#id_isbn_button');
|
||||||
|
@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue