我试图通过AJAX将脚本作为JSON访问,这在Safari和其他浏览器上运行良好但不幸的是不能在Chrome中执行.它出现以下错误:
Refused to execute script from ‘*’ because its MIME type (‘application/json’) is not executable, and strict MIME type checking is enabled.
这是请求:
$.ajax({
url: "http://some_url/test.json?callback=?",
type: "GET",
dataType: 'json',
cache: true,
success: function (data, status, error) {
console.log('success', data);
},
error: function (data, status, error) {
console.log('error', data, status, error);
}
});
有人有解决方法吗?
解决方法:
通过添加一个回调参数,您告诉jQuery您要使用脚本元素而不是使用XMLHttpRequest的JSON请求来请求JSONP.
JSONP不是JSON.这是一个JavaScript程序.
更改您的服务器,以便为JSONP输出正确的MIME类型,即application / javascript.
(当你在它的时候,不要告诉jQuery你期待JSON,因为这是矛盾的:dataType:’jsonp’).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。