PHP Classes

File: js/registrar.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   PHP AJAX Login with JWT and Fetch API   js/registrar.js   Download  
File: js/registrar.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: 1,567 bytes
 

Contents

Class file image Download
document.getElementById('registrationForm').addEventListener('submit', function (e) { e.preventDefault(); const urlBase="http://localhost:8089/" const nome = document.getElementById('nome').value; const email = document.getElementById('email').value; const senha = document.getElementById('senha').value; const resenha = document.getElementById('resenha').value; if(senha!=resenha){ document.getElementById("mensagem").innerText="As senhas estăo diferentes" document.getElementById('id02').style.display='block' return; } const usuario = { nome: nome, email: email, senha: senha }; fetch('backend/Router/Usuarios/Registrar', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(usuario) }) .then(response => response.json()) .then(data => { if (data.status) { document.getElementById('message').textContent = 'Usuário registrado com sucesso!'; document.getElementById('nome').value=''; document.getElementById('email').value=''; document.getElementById('senha').value=''; document.getElementById('resenha').value=''; } else { document.getElementById('message').textContent = 'Erro ao registrar o usuário.'; } }) .catch((error) => { console.error('Error:', error); document.getElementById('message').textContent = 'Erro ao registrar o usuário.'; }); });