Advertisement
bstefano79

niente

May 25th, 2024 (edited)
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.91 KB | Software | 0 0
  1. const InputUserNameLogIn = document.querySelector('#username');
  2. const InputPasswordLogIn = document.querySelector('#password');
  3. const paragErrore = document.querySelector('#errore-log-in');
  4. const form = document.querySelector('#form-Log-in');
  5.  
  6.  
  7. let richiesta;
  8. let data;
  9. let conferma;
  10.  
  11.  
  12. form.addEventListener('submit', function(event) {
  13.     event.preventDefault();
  14.     const userNameLogIn = InputUserNameLogIn.value;
  15.     const passwordLogIn = InputPasswordLogIn.value;
  16.  
  17.     richiesta = new XMLHttpRequest();
  18.  
  19.     richiesta.open('POST', 'http://localhost/vsc/php/log-in.php', true);
  20.  
  21.     richiesta.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  22.  
  23.     richiesta.onreadystatechange = function() {
  24.         if (richiesta.readyState === 4) {
  25.             if (richiesta.status === 200) {
  26.                 console.log(richiesta.responseText);
  27.                 conferma = richiesta.responseText;
  28.  
  29.                 constlocationHeader = richiesta.getResponseHeader('Location');
  30.                 if (locationHeader) {
  31.                      window.location.href = locationHeader;
  32.                 } else {
  33.                      console.log(richiesta.responseText);
  34.                 }
  35.  
  36.             } else {
  37.                 console.error('Errore durante la richiesta. Codice di stato:', richiesta.status);
  38.             }
  39.         }
  40.     };
  41.  
  42.     data = "username=" + encodeURIComponent(userNameLogIn) + "&password=" + encodeURIComponent(passwordLogIn);
  43.     richiesta.send(data);
  44.  
  45.     console.log('Il submit del form รจ stato bloccato. '+userNameLogIn+' '+passwordLogIn);
  46.  
  47.     gestioneFront(event)
  48. });
  49.  
  50. // Funzione aggiornata per gestire il front-end in base al risultato del login
  51. function gestioneFront(event) {
  52.     if (conferma > 0) {
  53.         console.log('Accesso eseguito');
  54.     } else {
  55.         paragErrore.innerText = 'Credenziali non corrette';
  56.         paragErrore.style.color = 'red';
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement