数据从ajax调用成功检索。 在ajax成功,我需要重定向到'/帐户/索引',但重定向不工作在Ajax成功。 是否有任何替代window.location.href?页面重定向不适用于ajax成功的mvc
$.ajax({
url: "/Register/Register",
async: false,
type: "POST",
data: JSON.stringify(RegisterMember),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (s) {
console.log(s);
//LoadprojectsGrid();
// End For
if (s.MessageCode == 1) {
event.preventDefault();
window.location.href = '/Account/Index';
}
else if (s.MessageCode == 2) {
$('.cssload-loader').remove();
$('#overlay').remove();
$.growl.error({ message: s.Message });
}
else
{
$('.cssload-loader').remove();
$('#overlay').remove();
$.growl.error({ message: s.Message });
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
$('.cssload-loader').remove();
$('#overlay').remove();
}
});
'window.location.href ='newUrl''应该工作。你确定你的if条件返回'true'吗? – Shyju
是条件返回true – Ejazkhan
根据W3C:window.location.href属性返回当前页面的URL。 –