Can you redirect with ajax?
You can manage a redirect request after a jQuery call by using an approach by JSON. ajax({ type: “POST”, url: reqUrl, data: reqBody, dataType: “json”, success: function (data, textStatus) { if (data. redirect) { // data. redirect contains the string URL to redirect to window.
How redirect ajax in PHP?
You can pass the URL or any other parameter from PHP into your JavaScript code and then redirect your browser. The data variable in success() function in ajax request should contain a needed value. After your PHP script is finished, make an output of URL that you want to redirect on.
Why does redirecttoaction not work after Ajax post?
The last one, RedirectToAction, actually calls IncidentList () that’s supposed to return my view but nothing happens. I tried to replace RedirectToAction with View, Redirect… nothing better happened. I tried to reload from my AJAX success callback function, but the behaviour wasn’t what I expected, and I prefer to do it from my Controller.
How to disable redirect for Ajax in JavaScript?
Using the following code in your global.asax you can disable the redirect for AJAX requests: This allows you to return 401 responses for AJAX requests, which your javascript can then handle by reloading the page.
What to do when you get a redirect request in JavaScript?
If you ever get returned contentType of text/html when you’re expecting JSON, you are most likely being redirected. In my case, I just simply reload the page, and it gets redirected to the login page. Oh, and check that the jqXHR status is 200, which seems silly, because you are in the error function, right?
What does jQuery do when redirecting to JSON?
JQuery is looking for a json type result, but because the redirect is processed automatically, it will receive the generated html source of your login.htm page. One idea is to let the the browser know that it should redirect by adding a redirect variable to to the resulting object and checking for it in JQuery: