Data is successfully retrieved from ajax call. In ajax success i need to redirect to '/Account/Index', but redirection not working in ajax success. Is there any alternative for window.location.href?
$.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();
}
});
Without href:
window.location = '/Account/Index';
Acording to some data I found it should be
window.location
and not
window.location.href
尝试使用 URL 助手,如下所示:
window.location.href = '@Url.Action("Index", "Account")';
Remove
event.preventDefault();
And use
window.location = '/Account/Index'; as stated by @marcos
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.