我们正在尝试在 jquery 代码中使用 Yammer Rest 服务的“current.json”
$.ajax({
url: "https://www.yammer.com/api/v1/networks/current.json",
jsonp: "callback",
type: "GET",
dataType: "jsonp",
data: "javascript",
contentType: 'application/json; charset=utf-8',
success: function (response) {
alert(1);
myObj = response;
readJson(response); // server response
},
error: function (xhr, errorText, status) {
alert(-1);
}
每次进入错误函数时,但是当我们看到状态代码时,它显示 200。 我们还可以在浏览器控制台中看到响应(JSON 格式)。
我们面临的确切错误是:
Refused to execute script from 'https://www.yammer.com/api/v1/networks/current.json?callback=jQuery110203706010680180043_1429617947980&_=1429617947981' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
有没有人能解决这个问题?
谢谢。
最佳答案
问题是因为您将 dataType
设置为 JSONP,但响应却以标准 JSON 格式返回。
Yammer API 似乎不支持 CORS 或 JSONP。您需要使用他们提供的 JS SDK通过 JavaScript 而不是 jQuery 向其发出请求。
关于javascript - 拒绝执行 'url' 中的脚本,因为其 MIME 类型 ('application/json' )不可执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29772152/