问题描述
我碰上一个情况下,我从未有过处理。我有谁需要做一个Ajax请求URL的客户。对于内部原因,URL重定向到另一个网址的状态code需要访问。正是这种多请求的情况通过Ajax请求处理的原生?
I bumped into a situation I've never had to address before. I have a customer who needs to make an ajax request to a URL. For internal reasons, that URL redirects to another URL whose status code needs to be accessed. Is this kind of multi-request scenario handled natively by Ajax requests?
一个快速测试使用jQuery似乎处理302,执行重定向并返回目标网页的内容(我只需要状态code生产,但内容是证明正确的页面被访问),但我找不到任何迹象表明我可以期待这个工作普遍。我不知道如果有,库中的客户端将使用什么。此外,其他客户端很可能在将来使用相同的URL,并需要将其处理方式相同。
A quick test using jQuery seems to handle the 302, do the redirection and return the content of the targeted page (I'll only need the status code in production, but the content is what "proves" the correct page is being accessed), but I can't find any indication that I can expect this to work universally. I don't know what, if any, library the client will use. Moreover, other clients are likely to use this same URL in the future and it needs to be handled the same way.
感谢。
推荐答案
您的可以的期望这普遍的工作,因为它不是jQuery的做处理。这是指定的所有的库使用AJAX调用底层 XmlHt prequest
浏览器对象的行为。
You can expect this to work universally, since it's not jQuery doing the handling. This is specified behavior of the underlying XmlHtpRequest
browser object that all libraries use for AJAX calls.
如果在的产地:// WWW。 w3.org/TR/XMLHtt$p$pquest/#url">URL 的传达的位置标头的与 XMLHtt prequest
起源并重定向不违反无限循环precautions,透明地遵循重定向同时观察的的。
我一直强调最相关的位位置,只要它不违反同源策略规则(它不应该在你的同一个域),则XmlHtt prequest将获得最后一个页面就被重定向到的内容。换句话说,这是你看到用jQuery现在的行为...它只是不jQuery的做这件事。
I've emphasized the most relevant bit here, as long as it doesn't violate same-origin policy rules (it shouldn't on your same domain), the XmlHttpRequest will get the content of final page it gets redirected to. In other words, it's the behavior you're seeing with jQuery now...it's just not jQuery doing it.
这篇关于阿贾克斯重定向处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!