admin管理员组文章数量:1356914
I created an iframe
in the custom HTML of 'blogspot'.
In the src
of the iframe
there is the link to 'Apps Script' (/.../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 '/.../exec' from origin 'https://...-script.googleusercontent' 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?
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/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/macros/s/.../exec' from origin 'https://...-script.googleusercontent' 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?
- 1 Would you be able to provide your whole script, and also your expected output so that we can further help you. – Patsytalk Commented Mar 28 at 4:21
- Use simple requests. – TheMaster Commented Mar 28 at 5:22
1 Answer
Reset to default 1If 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
- https://developers.google/apps-script/guides/web
本文标签: web applicationsMake POST from blogspot iframe to doPost from 39Apps Script39Stack Overflow
版权声明:本文标题:web applications - Make `POST` from blogspot iframe to `doPost` from 'Apps Script' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744059811a2583922.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论