反应303状态code jQuery中(从重定向prevent) [英] React to 303 status code in jquery ( Prevent from redirecting)

查看:221
本文介绍了反应303状态code jQuery中(从重定向prevent)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我请求发送到某个服务器,一个303的响应会来,然后结合所请求的响应200状态code。 有趣的是,我只看到这对我的开发人员控制台的网络视图中。当检查状态code和我的$就响应()请求,就会有第二个请求的响应,以及​​一个200 HTTP状态code。

when I send requests to a certain server, a 303 response will come, followed by the requested response in combination with a 200 status code. Funny thing is that I only see this on my developer console's network view. When checking the statuscode and response of my $.ajax() request, there will be the response of the second request, as well as a 200 http status code.

现在的问题是,它似乎是第二个请求被缓存(虽然200的状态code),我真的需要它非超高速缓存。 所以我真的想介入到发生了HTTP 303状态code中的转发过程。我想我的jQuery函数来检查状态code,再发送明确的标头的GET请求,告诉服务器不缓存响应。

The problem is that it seems that the second request is being cached (though 200 status code), and I really need it to be non-cachable. Therefore I'd really like to intervene into the forwarding process that occurs with a http 303 status code. I'd like my jquery function to check for the status code, then send the get request with explicit headers, that tell the server not to cache the response.

嗯,我只是不知道如何做到这一点,因为(如上所述)的jQuery.ajax方法与转发的请求的响应和状态code(200)作出回应。

Well, I just don't know how to do this, since (as mentioned above) the jQuery.ajax method will respond with the forwarded request's response and status code (200).

您能帮我吗?

修改

10.3.4 303看其他

10.3.4 303 See Other

要的请求的响应可在不同的URI被发现和   应该利用该资源一个GET方法检索。这种方法   存在主要是为了使一个POST激活脚本的输出以   用户代理重定向到所选择的资源。新的URI是不是一个   对于最初请求的资源替代参考。 303   响应必须不被缓存,而是响应于所述第二   (转移)请求可能是缓存。

The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be cacheable.

也许我需要以某种方式prevent用户代理重定向从自己,所以我可以做的重定向?

maybe I need to somehow prevent the user agent from redirecting himself, so I can do the redirect?

或者是有没有办法简单地告诉服务器/浏览器不缓存来自客户端的第二个请求?或者从重定向我的要求prevent呢?或重定向之前至少修改第二个请求?

Or is there a way to simply tell the server/browser not to cache the second request from client-side? or to prevent it from redirecting my request? or at least modify the second request before redirecting?

推荐答案

在300范围内的反应,目的是要透明。 AFAIK,Web浏览器不公开任何人的JavaScript。因此,处理303是不是一个选项。

Responses in the 300 range are meant to be transparent. AFAIK, web browsers don't expose any of them to javascript. Thus, handling the 303 is not an option.

您是否尝试过缓存属性设置为false在ajaxSetup?它会附加到请求,$ P $从缓存响应pventing浏览器中的时戳。你也可以做到这一点手动自己。浏览器应在第一个请求的URL匹配到第2反应

Have you tried setting the cache property to false in the ajaxSetup? It will append a timestamp to the request, preventing the browser from caching the response. You can also do that manually yourself. The browser should match the first request url to the 2nd response

这篇关于反应303状态code jQuery中(从重定向prevent)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆