Chrome refuses to execute an AJAX script due to wrong MIME type
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'
).
AJAX error message on Chrome, MIME type checking is enabled
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.
Refused to execute script, strict MIME type checking is enabled?
You have a <script>
element that is trying to load some external JavaScript.
The URL you have given it points to a JSON file and not a JavaScript program.
The server is correctly reporting that it is JSON so the browser is aborting with that error message instead of trying to execute the JSON as JavaScript (which would throw an error).
Odds are that the underlying reason for this is that you are trying to make an Ajax request, have hit a cross origin error and have tried to fix it by telling jQuery that you are using JSONP. This only works if the URL provides JSONP (which is a different subset of JavaScript), which this one doesn't.
The same URL with the additional query string parameter callback=the_name_of_your_callback_function
does return JavaScript though.
How do I resolve a 'MIME type mismatch error' blocking an AJAX-requested resource from my Google Apps Script?
I believe your goal as follows.
- You want to request to the Web Apps using
jQuery.ajax()
instead offetch
.
For this, when your settings
is modified, how about the following modification?
Modified script:
var settings = {
'url': url,
'method': 'GET',
'dataType':"json",
'data': {spreadsheetId: "###SpreadsheetId###", sheetName: "###SheetName###"},
};
Sample script:var url = 'https://script.google.com/macros/s/###/exec';
var settings = {
'url': url,
'method': 'GET',
'dataType':"json",
'data': {spreadsheetId: "###SpreadsheetId###", sheetName: "###SheetName###"},
};
$.ajax(settings).done(res => {
console.log(res.values); // By this, you can retrieve the values of `{values: values}` from Web Apps.
}).fail(err => console.log(err));
Note:
- When you modified the Google Apps Script of Web Apps, please redeploy the Web Apps as new version. By this, the latest script is reflected to the Web Apps. Please be careful this.
- In above modified script, your Google Apps Script could be used.
- In this case, I could confirm that the above script worked with Chrome.
Reference:
- jQuery.ajax()
Disable Chrome strict MIME type checking
The server should respond with the correct MIME Type for JSONP application/javascript
and your request should tell jQuery you are loading JSONP dataType: 'jsonp'
Please see this answer for further details !
You can also have a look a this one as it explains why loading .js
file with text/plain
won't work.
Chrome 71 will refuse to execute script because its MIME type ('text/x-js') is not executable
For those who is facing the problem it is a well konown issue: "strict MIME type checking". Chrome enables strick mime type checking. There is ton of questions on stack over flow about it.
But it happens that it was still possible to avoid "strict MIME type checking" through worker api with importScripts.
For those who are still using chrome 70.0.3538.110 like me there is no strick mime type checking through the importScripts on the worker api. The new version of chrome fixes it. But it is still possible in firefox. I reported this behaviour to mozilla in case it was not expected
It was not clear for me but in our production machine our apache server has this mime type set: "text/x-js js". I simply replace it with application "application/javascript" js instead or "text/javascript js" which is obsolete by the way.
Ajax JSONP refuses to execute code because of MIME type
Best way is cURL , download the HTML content of an URL then ECHO it to your javascript then get what you want :D , or do all of it in PHP with this great PLUGIN : https://code.google.com/p/phpquery/wiki/Selectors
Getting a MIME type ('application/json') is not executable error. Any reason why?
That's a JavaScript file that contains a JSON array, not specifically a JSON file.
Rename the file to londonM.js
and you'll be good to go.
Related Topics
How to Break a String Across More Than One Line of Code in JavaScript
How to Toggle an Element's Class in Pure JavaScript
Doesn't JavaScript Support Closures with Local Variables
Jquery (Or Pure Js) Simulate Enter Key Pressed for Testing
Jquery Selector for Id Starts with Specific Text
Invalid Hook Call. Hooks Can Only Be Called Inside of the Body of a Function Component
What's the Cause of the Error 'Getaddrinfo Eai_Again'
How to Change the Content of a <Textarea> with JavaScript
Javascript: Which Browsers Support Parsing of Iso-8601 Date String with Date.Parse
Cloud Firestore Case Insensitive Sorting Using Query
How to Use Redirect in Version 5 of React-Router-Dom of Reactjs
Get All Attributes of an Element Using Jquery
Mobile Safari Autofocus Text Field
How to Get the (X, Y) Pixel Coordinates of the Caret in Text Boxes