PHP Classes

File: js/login.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   PHP AJAX Login with JWT and Fetch API   js/login.js   Download  
File: js/login.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP AJAX Login with JWT and Fetch API
Login users using AJAX to send JWT to a server API
Author: By
Last change:
Date: 5 months ago
Size: 905 bytes
 

Contents

Class file image Download
document.getElementById("login").addEventListener("click", async function (e) { e.preventDefault(); const urlBase="http://localhost:8089/" const email = document.getElementById("email").value; const password = document.getElementById("senha").value; const lembrar = document.getElementById("lembrar").checked; const response = await fetch('backend/Router/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, senha: password,lembrar }) }); const data = await response.json(); if (data.status) { sessionStorage.setItem('token', data.token); window.location.href = "index.html"; } else { document.getElementById("mensagem").innerText="Login falhou:\n " + data.message document.getElementById('id02').style.display='block' } });