I created an iframe in the custom HTML of 'blogspot'.
In the src of the iframe there is the link to 'Apps Script' (https://script.google.com/macros/s/.../exec).
In the .gs of 'Apps Script', there is the doGet below:
function doGet() {
const html = HtmlService.createHtmlOutputFromFile("blogspot");
return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
The blogspot file is the HTML page of my blogger. I did this to avoid editing the HTML in blogger itself.
doGet is working correctly.
However, when I tried to do a POST using fetch inside the 'blogspot' HTML (iframe content), then I got the error below:
userCodeAppPanel:1 Access to fetch at 'https://script.google.com/macros/s/.../exec' from origin 'https://...-script.googleusercontent.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I looked for other CORS resolutions here on the forum, but I didn't find what I'm looking for.
How can I solve the problem?
-
1Would you be able to provide your whole script, and also your expected output so that we can further help you.Patsytalk– Patsytalk2025年03月28日 04:21:33 +00:00Commented Mar 28, 2025 at 4:21
-
Use simple requests.TheMaster– TheMaster2025年03月28日 05:22:00 +00:00Commented Mar 28, 2025 at 5:22
1 Answer 1
If you want to make a POST request to a Google Apps Script web application, it should include a doPost function
Example
function doPost(e){
console.log(JSON.stringify(e, null, " ");
return ContentService.createTextOutput('Hello world!')
}
Reference
Comments
Explore related questions
See similar questions with these tags.