Ajax请求重定向

I am doing a Ajax request, in the response depending on some condition. I might send a 301 status code with a location(redirect) URL. But when I do that there is a ajax request to the redirect URL, but I want it to be a normal request not a ajax request.

Is there a way to do that?

Javascript can't see the redirect response, only the final response from the URL the browser was redirected to. Javascript can try to recognize the situation by analyzing the response content: Maybe it expects JSON but gets HTML (e.g. a login page :-) )

To do it right you'd need to modify the service to return a non-redirect response code to the Javascript which it can then handle (e.g. 401 when the session expires and the user must log in again)

it's pretty easy, you might want the server to return an url instead of performing redirection, end then use window.location to perform redirection in javascript :).