我有以下问题:我做了一个 jQuery ajax 帖子,如果成功,我需要将浏览器的位置更改为索引 View 。 这是 JavaScript:
$.post(CreateReleaseNotificationURL, Notifications_Form.serialize(), function (response) {
if (response.indexOf("Error") == 0) {
$("#NewNotification_CreateStatus").html(response);
}
else {
window.location.assign('@Url.Action("Index")');
//window.location = window.location;
}
})
.fail(function () {
$("#NewNotification_CreateStatus").html("An error has occured.<br /> Please contact the system administrator<br /> if the problem persists.");
});
但是,什么也没有发生!我缺少什么?
PS:我也尝试过使用location.href,但没有成功。
最佳答案
检查一下:
window.location.href = '@Url.Action("Index", "ControllerName")';
关于javascript location href 不适用于 jquery ajax post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18206807/