对于Internet Explorer,iframe中的getJSON调用失败

时间:2014-10-26 14:06:12

标签: javascript jquery internet-explorer iframe getjson

我正在 domainA 上运行一个小网页,使用

加载一些数据
 $.getJSON('http://domainA/data?callback=?', function ( data ) { // do stuff });

现在,我想使用iFrame将此网页集成到 domainB 上。这对Firefox和Chrome也非常有效。但是,Internet Explorer 11的调用失败。在 domainA 中使用iframe根本没有问题。所以我怀疑这个问题与一些跨域限制有关,我试图通过在响应头中添加Access-Control-Allow-Origin http://domainA来解决它,但遗憾的是没有帮助。

我也很困惑,为什么这会导致跨域问题,因为代码正在使用iframe运行。

为了清楚起见,我想提供一个更完整的例子。我在 domainB

上有以下代码
<iframe src="http://domainA"></iframe>

domainA 上时,我有以下代码:

$(document).ready(function(){
  var url = "http://domainA/api/data.json";
  $.getJSON(url, function(data) {
    console.info(data);
  }).error(function (xhr, textStatus) {
    console.info(textStatus);
  });
});

如果我使用Internet Explorer加载页面http://domainB,那么我会在控制台中获得'parsererror'。在每个其他浏览器上,我得到预期的数据输出。

0 个答案:

没有答案