Chrome refuses to execute an AJAX script due to wrong MIME type
Solution 1:
By adding a callback argument, you are telling jQuery that you want to make a request for JSONP using a script element instead of a request for JSON using XMLHttpRequest.
JSONP is not JSON. It is a JavaScript program.
Change your server so it outputs the right MIME type for JSONP which is application/javascript
.
(While you are at it, stop telling jQuery that you are expecting JSON as that is contradictory: dataType: 'jsonp'
).
Solution 2:
If your proxy server or container adds the following header when serving the .js file, it will force some browsers such as Chrome to perform strict checking of MIME types:
X-Content-Type-Options: nosniff
Remove this header to prevent Chrome performing the MIME check.
Solution 3:
FYI, I've got the same error from Chrome console. I thought my AJAX function causing it, but I uncommented my minified script from /javascripts/ajax-vanilla.min.js
to /javascripts/ajax-vanilla.js
. But in reality the source file was at /javascripts/src/ajax-vanilla.js
. So in Chrome you getting bad MIME type error even if the file cannot be found. In this case, the error message is described as text/plain
bad MIME type.
Solution 4:
For the record and Google search users, If you are a .NET Core developer, you should set the content-types manually, because their default value is null or empty:
var provider = new FileExtensionContentTypeProvider();
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
Solution 5:
I encountered this error using IIS 7.0 with a custom 404 error page, although I suspect this will happen with any 404 page. The server returned an html 404 response with a text/html mime type which could not (rightly) be executed.