在ajax请求中检测到重定向? [英] Detecting a redirect in ajax request?
问题描述
我想使用jQuery来获取URL,并明确检查它是否响应302重定向,但是不遵循重定向.
I want to use jQuery to GET a URL and explicitly check if it responded with a 302 redirect, but not follow the redirect.
jQuery的$.ajax
似乎总是遵循重定向.如何防止这种情况,并在不遵循重定向的情况下看到重定向?
jQuery's $.ajax
appears to always follow redirects. How can I prevent this, and see the redirect without following it?
标题为"jquery ajax redirect"的标题存在各种问题,但它们似乎都涉及实现其他目标,而不仅仅是直接检查服务器给出的状态.
There are various questions with titles like "jquery ajax redirect" but they all appear to involve accomplishing some other goal, rather than just directly checking the status that a server gives.
推荐答案
AJAX请求永远没有机会不遵循重定向(即,它必须遵循重定向).可以在此答案中找到更多信息 https://stackoverflow.com/a/2573589/965648
The AJAX request never has the opportunity to NOT follow the redirect (i.e., it must follow the redirect). More information can be found in this answer https://stackoverflow.com/a/2573589/965648
这篇关于在ajax请求中检测到重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!