Search code examples
javascripthtmljsonajaxjsonp

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.

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


Solution

  • You are telling jQuery to read it as JSONP.

    JSON and JSONP are different.

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

    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.