最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

web applications - Make `POST` from blogspot iframe to `doPost` from 'Apps Script' - Stack Overflow

programmeradmin0浏览0评论

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?

Share Improve this question edited Mar 28 at 13:38 Wicket 38.7k9 gold badges80 silver badges194 bronze badges asked Mar 28 at 2:22 John SimonJohn Simon 1572 silver badges8 bronze badges 2
  • 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
Add a comment  | 

1 Answer 1

Reset to default 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

  • https://developers.google/apps-script/guides/web
发布评论

评论列表(0)

  1. 暂无评论