页面重定向不适用于ajax成功的mvc
问题描述:
数据从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();
}
});
答
没有HREF:
了window.location = '/帐户/索引';
+0
如果你想使用分配方法: http://www.w3schools.com/js/js_window_location.asp –
答
Acording一些数据,我发现它应该是
window.location
,而不是
window.location.href
答
尝试使用URL帮手如下:
window.location.href = '@Url.Action("Index", "Account")';
答
删除
event.preventDefault();
并使用
window.location = '/Account/Index'; as stated by @marcos
'window.location.href ='newUrl''应该工作。你确定你的if条件返回'true'吗? – Shyju
是条件返回true – Ejazkhan
根据W3C:window.location.href属性返回当前页面的URL。 –