0

我正在做一个 Ajax 请求,在响应中取决于某些条件。我可能会发送带有位置(重定向)URL 的 301 状态代码。但是当我这样做时,重定向 URL 有一个 ajax 请求,但我希望它是一个普通请求而不是 ajax 请求。

有没有办法做到这一点?

4

2 回答 2

1

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)

于 2012-08-21T19:49:59.160 回答
1

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 :).

于 2012-08-21T19:52:34.177 回答