Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 被拒绝从'执行脚本*';因为它的MIME类型(';application/json';)是不可执行的,并且是严格的MIME类型_Javascript_Ajax_Json_Rest_Confluence Rest Api - Fatal编程技术网

Javascript 被拒绝从'执行脚本*';因为它的MIME类型(';application/json';)是不可执行的,并且是严格的MIME类型

Javascript 被拒绝从'执行脚本*';因为它的MIME类型(';application/json';)是不可执行的,并且是严格的MIME类型,javascript,ajax,json,rest,confluence-rest-api,Javascript,Ajax,Json,Rest,Confluence Rest Api,请在下面找到我的代码,以获得来自confluence rest api的响应: <script type="text/javascript" src="Scripts/jquery.min.js"></script> <script> $.ajax({ type: "GET", url: "https://blog.xxxxx.com/rest/api/content?type=blogpost&spaceKey

请在下面找到我的代码,以获得来自
confluence rest api
的响应:

<script type="text/javascript" src="Scripts/jquery.min.js"></script>
<script>
    $.ajax({
        type: "GET",
        url: "https://blog.xxxxx.com/rest/api/content?type=blogpost&spaceKey=xxxxx&expand=space,body.view,version,container",
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        jsonp: 'jsonp-callback',
        async: false,
        success: function (result) {
            console.log(result);
        },
        error: function (xhr, errorText) {
            console.log('Error ' + xhr.responseText);
        }
    });
</script>
仍然得到相同的错误

响应主体

results: [{id:3342352, type:blogpost, title:The stocks that are set to fly (or crash),…},…]
0: {id:3342352, type:blogpost, title:The stocks that are set to fly (or crash),…}
1: {id:3833861, type:blogpost, title:Before earnings season, it's downgrade season,…}
2: {id:3833876, type:blogpost, title:Petrobras - what goes up, must come down,…}
3: {id:3833882, type:blogpost, title:Fishing for Income in the FTSE 100,…}
4: {id:4489219, type:blogpost, title:A Ray of Light Among the Gathering German Gloom,…}
5: {id:4489234, type:blogpost, title:Insider trading falls as buybacks dominate share prices,…}
6: {id:4489241, type:blogpost, title:El Clasico: Nike vs Adidas,…}
7: {id:4489248, type:blogpost, title:Dollar uncertainty exposes investors' complacency,…}
8: {id:4489254, type:blogpost, title:Worst yet to come for the Australian miners,…}
9: {id:4489258, type:blogpost, title:Using Aggregate List Views to Find Lurking Risks,…}
size: 10
start: 0
如何解决
MIME类型('application/json')不可执行,并且在
confluence rest api中启用了严格的MIME类型检查的问题?

我在以下内容中看到了这一点:

仅在GET上可用。返回的内容类型 必须是application/javascript


同时检查JSONP已启用

https://blog.xxxxx.com/rest/api/content?type=blogpost&spaceKey=xxxxx&expand=space视图、版本、容器
正在返回JSON

您正在告诉jQuery将其读取为JSONP

JSON和JSONP是不同的

您需要更改服务器以使用JSONP响应,或者更改JavaScript以使用JSON

请求的资源上不存在“Access Control Allow Origin”标头


如果将客户端更改为使用JSON,则还需要更改服务器(
blog.xxxxx.com
)以提供CORS头,该头授予浏览器忽略同源策略的权限

可能重复的问题:@MichaelPlakhov-这是重复的,但问题中给出的解决方案不起作用。我的问题是专门针对
confluence rest api
contentType的:“application/json;charset=utf-8”
毫无意义。您正在发出GET请求。没有请求主体来描述f的内容类型。我遇到了相同的问题。我现在无法解决它。继续寻找一个有用的答案:|我可以在
网络
选项卡中看到响应,但无法将其附加到我的页面上。能否将响应正文添加到问题中,以便我们可以检测它是json还是jsonp?能否检查网络请求(在网络开发工具面板中)并确保它有jsonp回调参数,就像您正在讨论的关于jsonp的代码一样。您是否检查了来自confluence api的响应中是否存在“访问控制源”?确认错误为“请求的资源上不存在“访问控制允许源”标题”,并且confluence api响应中的标题包含“访问控制源:*”(不是您的站点响应,而是blog.xxxxx.com)我可以在
Network
选项卡中看到响应,但无法将其附加到我的页面上。@user3108072-当然可以。如果浏览器没有收到响应,您将不会收到收到的错误消息。正如我所说的,问题在于(取决于您使用的代码版本)数据不是您试图解析的格式,或者您的网站不允许访问数据,因此您的浏览器不会让您的网站的JavaScript获取数据。@user3108072-您仍在发出get请求。说请求主体是
“Content-Type”:“application/javascript;charset=utf-8”
仍然是胡说八道,因为您仍然没有请求主体。请注意,虽然OP做了很多错事,但这至少部分可能是
X-Content-Type-Options:nosniff
问题。如果使用非脚本
内容类型
,则使用该标题提供的响应不能插入到
标记中(JSONP中的必要步骤)。这就是“sctrict MIME类型检查”的由来。然而,这里的解决方案似乎是“提供(或期望)正确的MIME类型”(您真的有脚本还是真的有JSON?请下定决心),而不是“禁用严格的类型检查”。我在回答中提到的那些。如果您使用的是JSON或JSONP,请从选择开始。如果选择JSONP,那么就去掉所有的头文件,让服务器用JSONP响应。如果选择JSON,那么就去掉所有客户端的头文件设置,让服务器返回一个访问控制源文件头。
results: [{id:3342352, type:blogpost, title:The stocks that are set to fly (or crash),…},…]
0: {id:3342352, type:blogpost, title:The stocks that are set to fly (or crash),…}
1: {id:3833861, type:blogpost, title:Before earnings season, it's downgrade season,…}
2: {id:3833876, type:blogpost, title:Petrobras - what goes up, must come down,…}
3: {id:3833882, type:blogpost, title:Fishing for Income in the FTSE 100,…}
4: {id:4489219, type:blogpost, title:A Ray of Light Among the Gathering German Gloom,…}
5: {id:4489234, type:blogpost, title:Insider trading falls as buybacks dominate share prices,…}
6: {id:4489241, type:blogpost, title:El Clasico: Nike vs Adidas,…}
7: {id:4489248, type:blogpost, title:Dollar uncertainty exposes investors' complacency,…}
8: {id:4489254, type:blogpost, title:Worst yet to come for the Australian miners,…}
9: {id:4489258, type:blogpost, title:Using Aggregate List Views to Find Lurking Risks,…}
size: 10
start: 0