Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解释为文档但使用MIME类型application/json传输的资源:_Javascript_Json_Iframe - Fatal编程技术网

Javascript 解释为文档但使用MIME类型application/json传输的资源:

Javascript 解释为文档但使用MIME类型application/json传输的资源:,javascript,json,iframe,Javascript,Json,Iframe,我在(google Chrome)上运行了以下javascriptcode,并在控制台中收到以下错误: Resource interpreted as Document but transferred with MIME type application/json: 在尝试刷新iframe之前,代码中的所有内容都可以正常工作。那是我收到信息的时候。为了便于查看,我将代码缩短了很多: var filePath = document.URL; var ifram = '<iframe id

我在(google Chrome)上运行了以下
javascript
code,并在控制台中收到以下错误:

Resource interpreted as Document but transferred with MIME type application/json:
在尝试刷新iframe之前,代码中的所有内容都可以正常工作。那是我收到信息的时候。为了便于查看,我将代码缩短了很多:

var filePath = document.URL;

var ifram = '<iframe id="frame" width="100%" height="1" scrolling="yes"></iframe>';
document.write(ifram);
var iframe = parent.document.getElementById("frame");
iframe.height = 600;
iframe.width = '60%';
iframe.src = filePath;

function search_prices(){
    var given_info = iframe.contentDocument.getElementsByTagName("pre")[0].innerHTML;
    var item_info = JSON.parse(given_info);
    setTimeout("iframe.src = filePath;", 500);
}

iframe.onload = search_prices;
var filePath=document.URL;
var-ifram='';
文件编写(ifram);
var iframe=parent.document.getElementById(“框架”);
iframe.height=600;
iframe.width='60%';
iframe.src=文件路径;
函数搜索_prices(){
var given_info=iframe.contentDocument.getElementsByTagName(“pre”)[0].innerHTML;
var item_info=JSON.parse(给定_info);
setTimeout(“iframe.src=filePath;”,500);
}
iframe.onload=搜索价格;

我研究了关于同一个错误的类似问题,但我找不到任何对我有帮助的东西,因为我无法控制服务器。页面上的信息是我必须处理的。

我刚刚能够让代码正常工作。它会刷新所有内容,但每次刷新控制台时,我仍然会在控制台中看到相同的错误…你是认真地通过iframe加载JSON字符串吗?iframe的
src
应该是HTML文档,为什么要尝试将JSON加载到iframe中?您的站点充满了MIME类型的错误-您还将大量的
text/html
text/plain
项加载到它将出现的
元素中。我真的建议您阅读MIME类型和
内容类型
标题对浏览器的意义,因为您在函数上使用了jQuery。