Action Fetch only works the first time

Par mbde, il y a 3 ans


First of all thank you for any help you can give me. I want to be able to dynamically activate/deactivate the status of a partner.

On each status change, a Bootstrap modal opens.
It works the first time but as soon as I click on the input again the modal opens but the action no longer works. I need to refresh the page. And I'm stuck on this issue...

// Activation ou désactivation dynamique d'un partenaire //On boucle sur les input document.querySelectorAll(".form-switch-statut-partenaire input").forEach(input => { input.addEventListener("change", () => { //On récupère l'url de la route edit-statut const Url = input.dataset.path; const Modal = document.getElementById('exampleModal') const Footer = Modal.getElementsByClassName('modal-footer')[0].children[1] Footer.addEventListener("click", () => { $("[data-dismiss=modal]").trigger({ type: "click" }); //On lance la requête ajax fetch(Url) .then((response) => { console.log(response); return response.json() }).then(data => { console.log(data) const content = document.querySelector('#formCheck'); content.innerHTML = data.content; }).catch((err) => console.log('Erreur : '+ err)); }) }); });

Aucune réponse