1
I’m having trouble with window.location = "index.php"
, he is not redirecting the page login.php
for index.php
, see the code:
<script type="text/javascript">
$(function() {
$("#loginForm").on("submit", function(a) {
a.preventDefault(), $("#signinButton").attr("value", "Autenticando...");
var user = $("#username").val();
var pass = $("#password").val();
if (user == "") {
$("#message").css("display", "block"), $('#message').html("<div class='alert alert-danger'><i class='fa fa-warning'></i> Insira seu usuário do Twitter</div>"), $("#signinButton").attr("value", "Entrar");
return false;
}
else if (pass == "") {
$("#message").css("display", "block"), $('#message').html("<div class='alert alert-danger'><i class='fa fa-warning'></i> Insira sua senha do Twitter</div>"), $("#signinButton").attr("value", "Entrar");
return false;
} else {
$("#message").hide();
}
var b = $("#username").val();
0 == /^[a-zA-Z0-9_ ]*$/.test(b) ? ($("#message").css("display", "block"), $("#message").html("<div class='alert alert-danger'><i class='fa fa-warning'></i> Existem caracteres especiais no seu usuário. Se estiver usando <strong>@</strong> remova-o!</div>"), $("#signinButton").attr("value", "Entrar")) : $.ajax({
type: "POST",
url: "api/login.php",
dataType: "JSON",
data: $("#loginForm").serialize(),
success: function(a) {
1 == a.redirect ? window.location = "index.php" : ($("#message").css("display", "block"), $("#message").html(a.message)), $("#signinButton").attr("value", "Entrar");
}
})
})
})
</script>
Here is my answer code is much bigger than this but I will post only the check:
if (isset($cookies['auth_token'])) {
Cookies::set('auth_token', $cookies['auth_token']);
Cookies::set('password', $ttrPassword);
$_SESSION[SITE_NAME . '_session'] = $ttrUsername;
echo json_encode(array('status' => 'success','message'=> "<div class='alert alert-success'><i class='fa fa-check'></i> Autenticação bem sucedida, estamos te redirecionando</div>"));
} else {
echo json_encode(array('status' => 'error','message'=> "<div class='alert alert-danger'><i class='fa fa-warning'></i> Não foi possível autenticar com o Twitter.</div>"));
}
What problem, is in return json, or my javascript
is incorrect?
I’ve seen it, and it has nothing to do with my problem
– WillBB
same thing... does not redirect...
– WillBB
What do you mean? I don’t really understand.
– WillBB
Wow, dude vlw poe as answer q marco as solved
– WillBB