Get Refused to execute the script from '*' because its MIME type ('application / json') is not executable, and the strong MIME type is che

Please find below my code to get the answer from 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>

      

I called this and this one as a reference, but didn't resolve my isse. I am getting an error on the console Refused to execute script from 'https://blog.xxxxx.com/rest/api/content?type=blogpost&spaceKey=xxxxx&…d=space,body.view,version,container&callback=jsonpCallback&_=1413187692508' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

.

I've tried with type:post

, dataType:json

and dataType:jsonp

using jsonp: jsonp-callback

. None of them worked for me.

In Network

chrome developer tools tab I get resposne from confluence

but it doesn't print the same to console or page.

If I use dataType:json

I get an error XMLHttpRequest cannot load https://blog.xxxxx.com/rest/api/content?type=blogpost&spaceKey=xxxxx&expand=space,body.view,version,container. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost' is therefore not allowed access

on chrome.

Update Adding mime type application/json

for json

in IIS doesn't work.

Updated code

$.ajax({
            type: 'GET',            
            url: 'https://blog.xxxxx.com/rest/api/content?type=blogpost&spaceKey=xxxxx&expand=space,body.view,version,container',   
            dataType: 'jsonp',
            xhrFields: {                
                withCredentials: false
            },
            headers: {
                "Accept" : "application/json; charset=utf-8",
                "Content-Type": "application/javascript; charset=utf-8",
                "Access-Control-Allow-Origin" : "*"
            },
            success: function (result) {
                $('#blog').html(result);
            },
            error: function (xhr, errorText) {
                console.log('Error ' + xhr.responseText);
            }
        });

      

The error still occurs.

Response body

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 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

      

How can I solve the problem MIME type ('application/json') is not executable, and strict MIME type checking is enabled

inconfluence rest api

+3


source to share


2 answers


https://blog.xxxxx.com/rest/api/content?type=blogpost&spaceKey=xxxxx&expand=space,body.view,version,container

returns JSON.

You are telling jQuery to read it as JSONP.

JSON and JSONP are different.



You either need to change the server to respond with JSONP, or change JavaScript to expect JSON.

No "Access-Control-Allow-Origin" header is present on the requested resource

If you change the client to expect JSON, you also need to change the server ( blog.xxxxx.com

) to provide CORS headers that give the browser the ability to ignore the same origin policy.

+3


source


I can see this in the Docs :

Only available in GET. The returned content type MUST be application / javascript.



Also check the included JSONP

+1


source







All Articles