在ajax请求中检测重定向? [英] Detecting a redirect in ajax request?

查看:40
本文介绍了在ajax请求中检测重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 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屋!

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