[英]Ajax call does not work properly
I have written this code for authentication.It works well till calling of function "a", control goes to function a but it ignores redirect line..I checked using alert that it executes "a" function. 我已经编写了这个代码用于身份验证。它在调用函数“a”之前运行良好,控制转到函数a但它忽略重定向行。我使用alert检查它执行“a”函数。 Why this is happening? 为什么会这样?
$('#loginbtn').click(function() {
var userName = document.getElementById('uid').value;
var password = document.getElementById('pwd').value;
$.ajax({
type : "POST",
url : "/LoginNew.aspx/Authenticate",
data : {
userName: userName ,
password: password
},
async : false,
contentType : "application/json; charset=utf-8",
dataType : "json",
success : a,
error : function(e) {
alert(e.valueOf());
}
});
function a() {
window.location.href = "Login.aspx";
}
});
success : a() //function is called like this
尝试使用
success : function(){window.location.href = "Login.aspx"};
删除.href
部分,你需要指定一个路径,就像这样
window.location = "/Login.aspx";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.