[英]AJAX error message on Chrome, MIME type checking is enabled
Every time I run this code I get this error message: 每次我运行此代码时,都会收到以下错误消息:
index.html:1 Refused to execute script from ' http://quotesondesign.com/wp-json/posts?callback=jQuery321021689358047216856_1511579115978 ' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled. index.html:1拒绝从' http://quotesondesign.com/wp-json/posts?callback=jQuery321021689358047216856_1511579115978 '执行脚本,因为其MIME类型('application / json')无法执行,并且严格的MIME类型检查是启用。
$.ajax({
url: "http://quotesondesign.com/wp-json/posts",
type: "GET",
dataType: 'jsonp',
cache: true,
success: function (data, status, error) {
console.log('success', data);
}
});
I cant find a solution, please help me resolve this bug. 我找不到解决方案,请帮助我解决此错误。
You are telling jQuery to read it as JSONP. 您正在告诉jQuery将其读取为JSONP。
JSON and JSONP are different. JSON和JSONP不同。
You need to either change the server to respond with JSONP or change the JavaScript to expect JSON. 您需要更改服务器以使用JSONP进行响应,或者更改JavaScript以使用JSONP。
If you change the client to expect JSON, then you also need to change the server (quotesondesign.com) to provide the CORS headers that give the browser permission to ignore the Same Origin Policy. 如果更改客户端以使用JSON,则还需要更改服务器(quotesondesign.com)以提供CORS标头,该标头赋予浏览器忽略相同原点策略的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.