简体   繁体   中英

How to redirect to another page after ajax call is finished

I am invoking a void method by using JQuery ajax call as below:

var options = {

    url: "/Account/Login",
    data: formvalues,
    type: "post"
};

$.ajax(options).done(function () {

// how to redirect the user to home page?

});

I want to redirect the user to the home page after he is logged in. Is there a way to accomplish this in jQuery? I tried window.location.replace , but it simply displays the page without maintaining any history as such. Is there any other way to do it?

You should be a able to set window.location

window.location = '/Home/Index';

To clarify:

Though Window.location is a read-only Location object, you can also assign a DOMString to it. This means that you can work with location as if it were a string in most cases: location = ' http://www.example.com ' is a synonym of location.href = ' http://www.example.com '.

https://developer.mozilla.org/en-US/docs/Web/API/window.location

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

Answer found here .

使用windows.location.href代替

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