无法登录嵌入到iframe中的网站,而且许多ajax帖子请求在iframe内无法工作,这只是chrome中的问题



我有两个站点https://site1.com(PHP网站(和http://site2.com(PHP网站(。我已经使用iframe 将站点1嵌入到站点2中

<iframe  src="https://site1.com" seamless width='100%' height="700px" frameborder="0"></iframe>

现在的问题是我无法登录到iframe中的site2,而且一些ajax请求响应是空的

这在Firefox浏览器中运行良好,仅在谷歌chrome浏览器中面临此问题

知道为什么会发生这种事吗?我还有其他可供选择的解决方案吗?

我遇到了与您类似的问题,在这篇MDN文章CORS(MDN(之后,我能够解决我的CORS问题,请参阅"使用凭据请求"一节。在那里,您会发现您必须使用Credentials设置xhr选项。以下是他们使用的示例:

var invocation = new XMLHttpRequest();
var url = 'http://bar.other/resources/credentialed-content/';
function callOtherDomain(){
if(invocation) {
invocation.open('GET', url, true);
invocation.withCredentials = true;
invocation.onreadystatechange = handler; // Needs to be implemented
invocation.send(); 
}
}

最新更新