0

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?

ataravati
  • 8,656
  • 6
  • 51
  • 80
Sam
  • 3,926
  • 11
  • 39
  • 71

3 Answers3

0

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

beautifulcoder
  • 9,954
  • 3
  • 18
  • 27
0
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

Answer found here.

Community
  • 1
  • 1
NightOwl888
  • 53,678
  • 21
  • 130
  • 204
-1

use windows.location.href instead

Vaibhav J
  • 1,294
  • 8
  • 13