javascript location href 不适用于 jquery ajax post

标签 javascript jquery asp.net-mvc

我有以下问题:我做了一个 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/

相关文章:

jquery - 调用jvectormap的addMarker函数

asp.net-mvc - 是否可以将 XDocument 作为参数传递给 ASP.NET MVC 中的操作?

jquery - ASP.NET MVC 客户端电子邮件验证不起作用

asp.net-mvc - 使用ASP.NET MVC2,如何使过滤器可用于可入侵的URL?

javascript - Bootstrap 菜单栏在折叠时重叠 Logo

javascript - react native 出现奇怪的样式表错误

javascript - 在高 map 中使用自定义边界

javascript - 制作一个没有 ng-show 或 ng-hide 的 AngularJS "hide and show"解决方案

javascript - 如何在动态内容插入后重新定位 Bootstrap Popover?

javascript - jquery函数根据特殊字符改变文本颜色