gpt4 book ai didi

javascript - AJAX : 301/302 header redirection (cross-domain) failing in some Webkit browsers

转载 作者:行者123 更新时间:2023-12-01 15:14:52 26 4
gpt4 key购买 nike

尝试通过 302 从一台服务器重定向到另一台没有内容的服务器,仅用于跟踪目的,我担心会失去一些使用 Apple iOS 设备和某些 Webkit/Chrome 浏览器的访问者。

HTTP/1.1 302 Moved Temporarily
Date: Tue, 26 Mar 2013 20:00:03 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.2.6
Expires: Tue, 03 Jul 2001 06:00:00 GMT
Last-Modified: Tue, 26 Mar 2013 20:00:03 GMT
Cache-Control: no-store
Pragma: no-cache
P3P: CP="STP CUR OUR"
x-own: 46.163.123.40
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Location: http://target2.com
Connection: close
Content-Type: text/html; charset=iso-8859-1

在 Firefox 和 IE 上,重定向是可以的。从 domainA 重定向到 domainA 也可以。跨域重定向在 Webkit/Chrome/Mobile Safari 浏览器上失败:-(

javascript 片段如下所示:

testRedirection=function(url)
{
var xmlhttp = null;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();//ff,webkit
else if (window.ActiveXObject)
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");//ie
if(xmlhttp)
{
xmlhttp.open("HEAD",url,true);//tried HEAD, GET, POST
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200 || (xmlhttp.status>200 && xmlhttp.status<400))
alert("arrived with status "+xmlhttp.status);
else
alert("failed with status "+xmlhttp.status);
};
};
xmlhttp.send();
};
//\
};

无论如何,在 iPhone 和 iPad 设备以及 Chrome 上,我记录了流量,但它永远不会到达 target2.com,在没有错误或警告的情况下停止。

这只发生在跨域标题重定向中。是否有额外的 header 允许这样做?

最佳答案

这是一项安全功能。就脚本而言(例如 Javascript),该请求被认为是危险的并被阻止。仅允许在 >= 200 < 300 范围内的响应。

关于javascript - AJAX : 301/302 header redirection (cross-domain) failing in some Webkit browsers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15780705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com