Comunidad de diseño web y desarrollo en internet online

Login localStorage

Citar            
MensajeEscrito el 13 Jun 2017 01:17 pm
Hola a todos, necesito ayuda.
Tengo un login.html que hace una llamada al archivo externo auth.php y devuelve 'sucess' o 'failed'. la llamada y respuesta funciona bien el problema lo tengo que luego no me redirecciona al index.html.
Alguien podria ofrecerme ayuda? gracias.

----login.html-----


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/ionic.css" />
<title>Login</title>

<script type="text/javascript">
var url = window.location.pathname;
var filename = url.substring(url.lastIndexOf('/') + 1);
if (localStorage.login == "true" && filename == 'login.html') {
window.location.href = "index.html";
} else if (localStorage.login == "false" && filename != 'login.html') {
window.location.href = "index.html";
}
</script>
</head>

<body>
<div class="content">
<div class="list list-inset">
<div style="text-align:center;">
<img src="img/logo.png" style="width:300px;"/>
</div>
<label class="item item-input">
<span class="input-label">Email</span>
<input type="email" placeholder="[email protected]" id="email">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" placeholder="password" id="password">
</label>
<label class="item-input" style="padding:5px;">
<button class="button button-block button-positive" id="login">Login</button>
</label>
<div style="text-align:center">
<a href="forget-password.html" class="button-clear button-royal">Forget Password ?</a> or <a href="signup.html" class="button-clear button-royal">Signup</a>
</div>
</div>
</div>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/auth.js"></script>
</body>

</html>

----auth.js----

$(document).ready(function(){
var url="http://miweb.com/message_system/auth.php";
//Login Function
$("#login").click(function(){

var email=$("#email").val();
var password=$("#password").val();
var dataString="email="+email+"&password="+password+"&login=";
if($.trim(email).length>0 & $.trim(password).length>0){
$.ajax({
type: "POST",
url: url,
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function(){ $("#login").html('Conectando...');},
success: function(data){
if(data=="success")
{
localStorage.login="true";
localStorage.email=email;
localStorage.username=email;
window.location.href = "index.html";
}
else if(data=="failed")
{
console.log("fallo");
window.location.href = "index.html";

$("#login").html('Login');
}
}
});
}return false;

});

-------------index.html-----------


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<script type="text/javascript">
var url = window.location.pathname;
var filename = url.substring(url.lastIndexOf('/') + 1);
if (localStorage.login == "true" && filename == 'login.html') {
window.location.href = "index.html";
} else if (localStorage.login == null) {
window.location.href = "login.html";
} else if (localStorage.login == "false" && filename != 'login.html') {
window.location.href = "login.html";
}
</script>
</head>
<body>
<h1>Index</h1>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/message_list.js"></script>
</body>
</html>

Por joseca

4 de clabLevel



 

chrome
Citar            
MensajeEscrito el 17 Jun 2017 04:07 pm
haz un console.log(data) aver que te da, veo que para ajax utilizas tag input;

Por aukun

Claber

200 de clabLevel



Genero:Masculino  

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.