Reputation: 115
Window.location doesn't work after a success respond when it call a ajax request, the success function it called.
when i execute on firefox on debugger step by step the window.location it works .
function login(){
var jason ={"usuario":document.getElementById("inputusuario").value,
"password": document.getElementById("inputpassword").value
};
json =JSON.stringify(jason);
console.log(json);
var onSuccess = function (data) {
console.log('Success');
window.location ='salas.html'
};
var onError = function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
alert("no se conecto");
};
var onBeforeSend = function () {
console.log("Loading");
};
var jason ={"usuario":document.getElementById("inputusuario").value,
"password": document.getElementById("inputpassword").value
};
json =JSON.stringify(jason);
$.ajax({
url: "../reservaciones/index.php/login",
type:"POST",
data: json,
cache: false,
async: false,
beforeSend: onBeforeSend,
error: onError,
success: onSuccess
});
};
Upvotes: 2
Views: 7468
Reputation: 868
You're missing the trailing ';' in
window.location ='salas.html'
Upvotes: 0
Reputation: 65351
I copied your code exactly, added the appropriate elements, and it worked just fine.
Try these:
1. Try window.location.assign()
. This has been known to fix this very problem.
2. Try running async: true
. From your code I see no reason why you'd want to run false
and sometimes that can cause timing issues.
Upvotes: 1