Hello everyone, I have the following question: I have a web application that I want when I log into the "index.html" home page to get the 'name' and 'email' and put it with jquery on 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 previous pages
Example: I have a login index that works with ajax and php:
apagebetweenindexandmain
andfinallyIhavemypaginaprincipal.htmlwhereIwanttoreculperatethelogindataofindex.html
Ihopetohavebeenclearthankyouforbeingabletohelp...
Myphplogincode:
<?phprequire'./connection.php';$email=$_POST['email'];$senha=$_POST['senha'];$stm=$pdo->prepare('SELECT*FROMusuario_appWHEREemail=:emailANDsenha=: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 get 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);
Is #pegaemail output giving the message 'undefined' error in ajax?