拒绝执行脚本,是否启用了严格的MIME类型检查? [英] Refused to execute script, strict MIME type checking is enabled?

查看:223
本文介绍了拒绝执行脚本,是否启用了严格的MIME类型检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我在控制台中收到此错误?

Why am I getting this error in console?


拒绝从
执行脚本' https://www.googleapis .com / customsearch / v1?key = API_KEY& q = flower& searchType = image& fileType = jpg& imgSize = small& alt = json '
因为其MIME类型('application / json')是不可执行的,并且启用了
严格的MIME类型检查。

Refused to execute script from 'https://www.googleapis.com/customsearch/v1?key=API_KEY&q=flower&searchType=image&fileType=jpg&imgSize=small&alt=json' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.


推荐答案

你有一个< script> 元素试图加载一些外部JavaScript。

You have a <script> element that is trying to load some external JavaScript.

你给它的URL指向JSON文件而不是JavaScript程序。

The URL you have given it points to a JSON file and not a JavaScript program.

服务器正确报告它是JSON,因此浏览器正在使用该错误消息中止而不是尝试执行JSON作为JavaScript(这将是发生错误)。

The server is correctly reporting that it is JSON so the browser is aborting with that error message instead of trying to execute the JSON as JavaScript (which would throw an error).

可能的一个原因是你正在尝试发出Ajax请求,已经尝试过交叉来源错误通过告诉jQuery你正在使用JSONP来修复它。这仅在URL提供JSONP(JavaScript的不同子集)时才有效,而这不是。

Odds are that the underlying reason for this is that you are trying to make an Ajax request, have hit a cross origin error and have tried to fix it by telling jQuery that you are using JSONP. This only works if the URL provides JSONP (which is a different subset of JavaScript), which this one doesn't.

带有附加查询字符串参数的相同URL callback = the_name_of_your_callback_function 确实会返回JavaScript。

The same URL with the additional query string parameter callback=the_name_of_your_callback_function does return JavaScript though.

这篇关于拒绝执行脚本,是否启用了严格的MIME类型检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆