Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const InputUserNameLogIn = document.querySelector('#username');
- const InputPasswordLogIn = document.querySelector('#password');
- const paragErrore = document.querySelector('#errore-log-in');
- const form = document.querySelector('#form-Log-in');
- let richiesta;
- let data;
- let conferma;
- form.addEventListener('submit', function(event) {
- event.preventDefault();
- const userNameLogIn = InputUserNameLogIn.value;
- const passwordLogIn = InputPasswordLogIn.value;
- richiesta = new XMLHttpRequest();
- richiesta.open('POST', 'http://localhost/vsc/php/log-in.php', true);
- richiesta.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- richiesta.onreadystatechange = function() {
- if (richiesta.readyState === 4) {
- if (richiesta.status === 200) {
- console.log(richiesta.responseText);
- conferma = richiesta.responseText;
- constlocationHeader = richiesta.getResponseHeader('Location');
- if (locationHeader) {
- window.location.href = locationHeader;
- } else {
- console.log(richiesta.responseText);
- }
- } else {
- console.error('Errore durante la richiesta. Codice di stato:', richiesta.status);
- }
- }
- };
- data = "username=" + encodeURIComponent(userNameLogIn) + "&password=" + encodeURIComponent(passwordLogIn);
- richiesta.send(data);
- console.log('Il submit del form รจ stato bloccato. '+userNameLogIn+' '+passwordLogIn);
- gestioneFront(event)
- });
- // Funzione aggiornata per gestire il front-end in base al risultato del login
- function gestioneFront(event) {
- if (conferma > 0) {
- console.log('Accesso eseguito');
- } else {
- paragErrore.innerText = 'Credenziali non corrette';
- paragErrore.style.color = 'red';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement