gpt4 book ai didi

php - Firefox 23 和 IE10 不再能很好地处理我的 XMLHttpRequest,我在 php 中有 CORS

转载 作者:行者123 更新时间:2023-11-28 20:20:32 25 4
gpt4 key购买 nike

我有一段java脚本,它只是从网站上获取ID并将其传递给单独域上的另一个php脚本:

JavaScript 已启用:

https://myspot.com

并且将会

http://theotherwebsite.edu

这或多或少是有效的,我必须使用以前的跨站点解决方案,但现在似乎在 Firefox 23 和 IE10 上不被认可。

之前的解决方案使用的是这样的东西:

 var isIE10 = false; //this is beacuse stupid IE10 now does not work with the window.XDomainRequest
/*@cc_on
if (/^10/.test(@_jscript_version)) {
isIE10 = true;
}
@*/
console.log(isIE10);
var isIE8 = window.XDomainRequest ? true : false;

var invocation=createCrossDomainRequest();

function createCrossDomainRequest(url, handler)
{
var request;
if ((isIE8) && (!isIE10)) //tried to hack my own isIE10 fix didnt work
{
request = new window.XDomainRequest();
}
else
{
request = new XMLHttpRequest();
}
return request;

}

function callOtherDomain()
{
if (invocation)
{
if("withCredentials" in invocation) //was taking a stab in the dark with this.
{
invocation.onload=outputResult;
invocation.open("GET", url, true);
invocation.send();

}

else if(isIE8)
{
invocation.onload = outputResult;
invocation.open("GET", url, true);
invocation.send();
}
else
{
invocation.open('GET', url, true);
invocation.onreadystatechange = handler;
invocation.send();
}
}
else
{
var text = "No Invocation TookPlace At All";
var textNode = document.createTextNode(text);
var textDiv = document.getElementById("textDiv");
textDiv.appendChild(textNode);
}
}
function handler(evtXHR)
{
if (invocation.readyState == 4)
{
if (invocation.status == 200)
{
outputResult();
}
else
{
alert("Invocation Errors Occured " + invocation.status + " state: " + invocation.readyState);
}
}
}

function outputResult()
{
var response = invocation.responseText;


//get JSON of response
var obj = JSON.parse(response);
var mtype = obj.messagetype;
var output = obj.message;
var url = obj.url;

if(mtype=="error")
{
parent.location=url;
}
else if(mtype=="warning")
{
var answer=confirm(output);
if(answer)
parent.location=url;

}


//var textDiv = document.getElementById("textDiv");
//textDiv.innerHTML += response;

}

callOtherDomain();所以我不确定这里发生了什么,我在 firefox 23 上的控制台中收到错误:

阻止加载混合事件内容“http://theotherwebsite.edu”

我知道这是因为主脚本是在 https 上加载的,而不是在 http 上加载的。但之前并没有在意。我还知道这个错误会在 Firefox 的地址栏中设置一个屏蔽,用户可以告诉它启用被阻止的内容。这对我来说不是一个可以接受的解决方案。另外,如果我把我愚蠢的小 php 脚本放在 https 下,那也是我需要的证书?

那么 IE10 就无法工作:

SCRIPT5:访问被拒绝。 着陆,第 64 行字符 421

所以我不确定我需要做什么才能让我的代码再次工作,让用户调整浏览器是不可行的,因为这是在企业范围内分发的,这是一个导航屏幕,让他们知道更改他们的浏览器密码基于 php 文件使用通过 ajax 从网站传递的 ID 访问的某些 ldap 条目。

我做了一些谷歌搜索,但什么也没找到,我发现的最多的是 php 句柄,以使网站我猜 CORS 兼容:

<?php
header('Access-Control-Allow-Origin: *');

我最初也实现了这一点。所以不确定要尝试什么或下一步要看哪里?返回的是一个简单的 JSON 字符串,我可以尝试这里描述的预检方法吗:

http://ppe.blogs.msdn.com/b/ie/archive/2012/02/09/cors-for-xhr-in-ie10.aspx

???如果我这样做,我不确定标题应该是什么样子。

我本来打算发布 firefox 23 响应 header ,但它永远不会发出请求,因为它直接阻止加载混合事件内容。所以我想我有两个问题需要解决,一个是 javascript 存在于 https 上并调用 http...这可能是我在 Firefox 中唯一的问题,不能 100% 确定我是否会遇到跨站点问题。

IE10 永远找不到网络请求 header ,我正在 IE10 中的 F12 键按下区域内查看网络下,然后在使用 xhr 调用加载页面之前单击开始捕获。

所以我想我是在问 Firefox23 和 IE10 发生了什么变化,导致我的代码不再工作?

最佳答案

Firefox 23+ 将阻止他们所谓的“事件混合内容”。即:从安全网页 (https) 请求的、托管在非安全 (http) 位置的内容。在这种情况下,“事件”本质上是指非媒体类型的所有内容(不是图像、音频或视频资源)。这是为了防止中间人攻击使用非安全子请求进入安全页面。

有关更多信息,请参阅Mixed Content MDN 上的文章。

由于请求在到达网络之前就被阻止,因此不会有任何响应 header /数据。

不确定 IE10,但是their documentation似乎表明他们出于同样的原因阻止此类请求,并表示:

Cross-domain, cross-port, and mixed protocol requests are not allowed.

关于php - Firefox 23 和 IE10 不再能很好地处理我的 XMLHttpRequest,我在 php 中有 CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18412510/

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