I am trying to implement the code here with Jquery.ajax
rather than fetch
.
I get the following error when I make the AJAX call:
The resource from “https://script.googleusercontent.com/macros/echo?...” was blocked due to MIME type (“application/json”) mismatch (X-Content-Type-Options: nosniff).
The Google Apps Script works fine with cURL, so I suspect it's some disagreement between my (very simple) GApps script and my client script.
Here is the GApps script:
function doGet(e) {
const id = e.parameter.spreadsheetId;
const sheetName = e.parameter.sheetName;
const sheet = SpreadsheetApp.openById(id).getSheetByName(sheetName);
const values = sheet.getDataRange().getValues();
return ContentService.createTextOutput(JSON.stringify({values: values})).setMimeType(ContentService.MimeType.JAVASCRIPT);
}
Note: I have tried changing the MimeType
on the last line to JSON
with no success.
Here are my AJAX settings for the call in the client script:
var settings = {
'cache': false,
'dataType': "jsonp",
'async': true,
'crossDomain': true,
'url': url,
'method': 'GET',
'headers': {
'accept': 'application/json',
'Access-Control-Allow-Origin': '*'
}
};
I'm working in Firefox. A similar error is thrown in Chrome. How can I resolve this?