-1
Hello guys I am with the following doubt I have a web application I want when logging in the home page "index.html" take the 'name' and 'email' and put with jquery in another page with php, ajax and jquery 'paginaprincipal.html' .
example: index.html
<form name="form-login" id="MyForm">
<input id="email" type="text" name="email" required>
<input id="senha" type="password" name="senha" required>
<button type="submit" id="btnLogin">Acessar</button>
</form>
paginaprincipal.html
<div id="pega">
Nome: <p id="nome"></p>
Email: <p id="nome"></p>
</div>
note: before the main page I still have two more previous pages
Example: I have an index with login that is working with ajax and php:
a page between index and main
and finally I have my paginaprincipal.html where I want to go back to the login data of index.html
I hope I’ve been clear thank you for anyone who can help...
my login php code:
<?php
require './connection.php';
$email = $_POST['email'];
$senha = $_POST['senha'];
$stm = $pdo->prepare('SELECT * FROM usuario_app WHERE email = :email AND senha = :senha');
$stm->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
$stm->bindParam(':senha', $_POST['senha'], PDO::PARAM_STR);
$stm->execute();
if ($linha = $stm->fetch(PDO::FETCH_ASSOC)) {
echo "Bem vindo {$linha['nome']}";
} else {
echo 'Erro ao efetuar login!';
}
my login js:
$('#btnLogin').click(function () {
var url = "http://localhost:/projeto/login.php";
$.post(url, $('#MyForm :input').serializeArray(), function (data) {
navigator.notification.alert(data, null, "MSG", "OK");
alert(data);
window.location.href = 'pagina_principal.html';
});
});
$('#MyForm').submit(function () {//PARA PAGINA NÃO CARREGAR NOVAMENTE
return false;
});
my ajax to pick up the data:
var reculpera = $("#MyForm").serialize();//form login #MyForm
$.ajax({
type: 'POST',
url: "http://localhost:/projeto/login.php",
data: reculpera
}).done(function (data) {
localStorage.setItem('nome', data.nome);
$("#pegaemail").text(localStorage.nome);
// alert(data.nome);
}).fail(function () {
alert("erro");
});
result of my ajax to play on that line
$("#pegaemail").text(localStorage.nome);
result #pegaemail is giving the message 'Undefined' error in ajax?
searching about found out I want to pick up with php and then with ajax and jquery return the values to the main page, would have as an example?
– Alan