【发布时间】:2013-03-04 17:03:39
【问题描述】:
Window.location在调用ajax请求时成功响应后不起作用,它调用的成功函数。
当我在调试器上的 firefox 上逐步执行 window.location 时,它可以工作。
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
});
};
【问题讨论】:
-
您的意思是您在控制台中看到“成功”但位置没有改变?
-
“不起作用”到底是什么意思?你有错误吗?它是否会将您定向到您不期望的页面?
-
如果要转到另一个页面,为什么还要使用 ajax?
-
@JackMarchetti 的 window.location 命令已执行但没有重定向。
-
@Musa 因为我想在更改页面之前比较凭据。它用于登录。
标签: javascript jquery ajax