Buenas, estoy haciendo una web app en la que necesito una vez se haya logueado el usuario redireccionarlo a otra página, pero si lohago en un script a través de una función no me funciona bien y me dijeron que lo podía hacer a través de div pero no tengo muy seguro como hacerlo, esto es para mi proyecto fin de carrera y necesito ayuda os pongo el código y a ver si me podeis ayudar con este problemilla y si avistais alguno más, un saludo.
Código:
<script>
function init()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady()
{
//oculta el splashscreen
navigator.splashscreen.hide();
}
</script>
<script>
function validarUsuario()
{
var READY_STATE_COMPLETE=4;
var peticion_http = null;
function inicializa_xhr()
{
if(window.XMLHttpRequest)
{
return new XMLHttpRequest();
}else if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function crea_query_string()
{
var user = document.getElementById("login");
var clave = document.getElementById("passw");
return "login=" + encodeURIComponent(user.value) +
"&passw=" + encodeURIComponent(clave.value);
}
function valida()
{
peticion_http = inicializa_xhr();
if(peticion_http)
{
peticion_http.onreadystatechange = procesaRespuesta();
peticion_http.open("POST", "http://www.sistemagrial.es/sig/service/autentication.php", true);
peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var query_string = crea_query_string();
peticion_http.send(query_string);
}
}
function procesaRespuesta()
{
if(peticion_http.readyState == READY_STATE_COMPLETE)
{
if(peticion_http.status == 200)
{
document.getElementById("respuesta").innerHTML = peticion_http.responseText;
}
}
}
}
var READY_STATE_COMPLETE=4;
var peticion_http = null;
function inicializa_xhr()
{
if(window.XMLHttpRequest)
{
return new XMLHttpRequest();
}else if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function crea_query_string()
{
var XX = JSON['usuario']['idMunicipio'];
return "XX=" + encodeURIComponent(XX.value);
}
function valida()
{
peticion_http = inicializa_xhr();
if(peticion_http)
{
peticion_http.onreadystatechange = procesaRespuesta();
peticion_http.open("POST", "http://www.sistemagrial.es/sig/service/get_cuadros/?idMunicipio=XX", true);
peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var query_string = crea_query_string();
peticion_http.send(query_string);
}
}
function procesaRespuesta()
{
if(peticion_http.readyState == READY_STATE_COMPLETE)
{
if(peticion_http.status == 200)
{
document.getElementById("respuesta").innerHTML = peticion_http.responseText;
}
}
}
</script>
</head>
<body onload="init();">
<div data-role="page" id="inicio">
<div data-role="header">
<h1>Login</h1>
</div>
<div data-role="content">
<form id="formulario" action="http://www.sistemagrial.es/sig/service/autentication.php" method="post">
<input type="text" id="login" name="login" placeholder="login" required>
<input type="password" id="passw" name="passw" placeholder="passw" required>
<input type="submit" value="Acceder" id="submit" onClick="validarUsuario()">
<input type="reset" name="Borrar" id="Borrar" value="Reset" class="boton">
</form>
</div>
</div>
<div id="respuesta">
</div>
</body>