简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM