简体   繁体   English

MIME 类型 ('application/json') 不可执行,并且启用了严格的 MIME 类型检查

[英]MIME type ('application/json') is not executable, and strict MIME type checking is enabled

I am getting the following error:我收到以下错误:

Refused to execute script from 'https://query1.finance.yahoo.com/v8/finance/chart/%5EBSESN?callback=jQuery34102269614347819202_1588033301698&_=1588033301699' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

My code - (added ?callback=? ) at the end of the url:我的代码 - (添加?callback=? )在 url 的末尾:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
var sensex =
  'https://query1.finance.yahoo.com/v8/finance/chart/%5EBSESN?callback=?';

jQuery(function ($) {
  $.getJSON(sensex, function (data) {
    console.log(data.chart.result.meta.regularMarketPrice);
    var sensex_value = data.chart.result.meta.regularMarketPrice;
    document.getElementById('sensex_value').innerHTML = String(sensex_value);
  });
});

API response looks like: API 响应如下所示:

{
    "chart": {
        "result": [
            {
                "meta": {
                    "regularMarketPrice": 31743.08,
                    "chartPreviousClose": 31327.22
                }
            }
        ]
    }
}

Here's a working version:这是一个工作版本:

<div id="sensex_value"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  var sensex =
    'http://www.whateverorigin.org/get?url=' +
    encodeURIComponent(
      'https://query1.finance.yahoo.com/v8/finance/chart/^BSESN'
    ) +
    '&callback=?';

  jQuery(function ($) {
    $.getJSON(sensex, function (data) {
      console.log(data.contents.chart.result[0].meta.regularMarketPrice);
      var sensex_value = data.contents.chart.result[0].meta.regularMarketPrice;
      document.getElementById('sensex_value').innerHTML = String(sensex_value);
    });
  });
</script>

Notable changes:显着变化:

  • data.contents.chart.result[0].meta.regularMarketPrice is the correct path data.contents.chart.result[0].meta.regularMarketPrice是正确的路径
  • I'm using whateverorigin.org to disable CORS .我正在使用whateverorigin.org来禁用CORS IMPORTANT: you shouldn't use it in production because websites like this are not reliable, instead, you should create your own backend API that would make requests to yahoo.重要提示:您不应该在生产中使用它,因为这样的网站不可靠,相反,您应该创建自己的后端 API 来向雅虎发出请求。

Everything else you got right.其他一切你都做对了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:MIME类型(&#39;application / json&#39;)无法执行,并且使用YQL语句启用了严格的MIME类型检查? - Error: MIME type ('application/json') is not executable, and strict MIME type checking is enabled with YQL statements? 拒绝执行脚本,因为它的 MIME 类型 ('application/gzip') 不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script because its MIME type ('application/gzip') is not executable, and strict MIME type checking is enabled 启用了严格的 mime 类型检查,拒绝执行来自 ' 的脚本<url> ' 它的 mime 类型 ('text/plain') 是不可执行的,并且</url> - strict mime type checking is enabled, refused to execute script from '<url>' its mime type ('text/plain') is not executable, and javascript:MIME类型(&#39;text / html&#39;)无法执行,并且启用了严格的MIME类型检查 - javascript: MIME type ('text/html') is not executable, and strict MIME type checking is enabled Angular 6:拒绝从“URL”执行脚本,因为它的 MIME 类型()不可执行,并且启用了严格的 MIME 类型检查 - Angular 6 : Refused to execute script from 'URL' because its MIME type( ) is not executable, & strict MIME type checking is enabled 拒绝执行脚本,因为 MIME 类型('text/html')不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script because MIME type ('text/html') is not executable, and strict MIME type checking is enabled GeoJSON 文件:拒绝执行脚本,因为其 MIME 类型 (&#39;&#39;) 不可执行,并且启用了严格的 MIME 类型检查 - GeoJSON file: Refused to execute script from because its MIME type ('') is not executable, and strict MIME type checking is enabled Dropbox:MIME 类型 (&#39;text/html&#39;) 不可执行,并且启用了严格的 MIME 类型 &gt; 检查 - Dropbox: MIME type ('text/html') is not executable, and strict MIME type > checking is enabled MIME类型(&#39;application / json&#39;)不可执行 - MIME type ('application/json') is not executable 拒绝从&#39;*&#39;执行脚本,因为它的MIME类型(&#39;application / json&#39;)不可执行,并且严格的MIME类型为che - getting Refused to execute script from '*' because its MIME type ('application/json') is not executable, and strict MIME type che
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM