简体   繁体   中英

Page redirection not working for mvc in ajax success

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

http://www.w3schools.com/js/js_window_location.asp

尝试使用 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM