1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
   | const factureForm = document.getElementById("factureForm");
const dateForm = document.getElementById("date");
const spinnerModal = new bootstrap.Modal(document.getElementById("spinner"));
const showAlertAction = document.getElementById("showAlertActions");
 
factureForm.addEventListener("submit", async (e) => {
  e.preventDefault();
 
  const formData = new FormData(factureForm);
  formData.append("add", 1);
 
 
  if (factureForm.checkValidity() === false) {
    e.preventDefault();
    e.stopPropagation();
    factureForm.classList.add("was-validated");
    return false;
  } else {
    document.getElementById("import-btn").value = "Patientez ...";
    spinnerModal.show();
    const data = await fetch("./ajax/import.php", {
      method: "POST",
      body: formData,
    });
    const response = await data.text();
    spinnerModal.hide();
    console.log(response);
    showAlertAction.innerHTML = response;
    setTimeout(function () {
      showAlertAction.innerHTML = "";
    }, 2000);
    document.getElementById("import-btn").value = "Enregistrer";
    factureForm.reset();
  }
}); | 
Partager