Advertisement
bstefano79

Untitled

May 23rd, 2024 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.11 KB | Software | 0 0
  1.  
  2. const paragErrore = document.querySelector('#errore-log-in');
  3. const bottoneSubmit = document.querySelector('#submit-btn');
  4.  
  5.  
  6. // console.log(InputPasswordLogIn);
  7.  
  8. bottoneSubmit.addEventListener('click', function(event){
  9.     event.preventDefault();
  10.  
  11.     const InputUserNameLogIn = document.querySelector('#username');
  12.     const InputPasswordLogIn = document.querySelector('#password');
  13.  
  14.     const richiesta = new XMLHttpRequest();
  15.  
  16.     richiesta.open('POST', 'http://localhost/vsc/php/log-in.php', true);
  17.  
  18.     richiesta.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  19.  
  20.     richiesta.onreadystatechange = function () {
  21.         if (richiesta.readyState === 4) {
  22.             if (richiesta.status === 200) {
  23.                 console.log(richiesta.responseText);
  24.             } else {
  25.                 console.error('Errore durante la richiesta. Codice di stato:', richiesta.status);
  26.             }
  27.         }
  28.     };
  29.  
  30.     const data = "username=" + encodeURIComponent(InputUserNameLogIn) + "&password=" + encodeURIComponent(InputPasswordLogIn);
  31.    
  32.     richiesta.send(data);
  33.    
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement