通过Google Apps脚本提交表单时收到访问控制允许原错误 服务器端:Google Apps脚本

通过HTMLform提交Google Sheets Google Apps ScriptOrigin https://example.com is not allowed by access-control-allow-origin. Fetch API cannot load https://script.google.com/macros/s/…/exec due to access control checks. Unhandled Promise Rejection: TypeError: Origin https://example.com is not allowed by access-control-allow-origin. 时,我收到以下错误:

XFrameOptionsMode.ALLOWALL

在服务器端,我已经设置了iframe以便将响应加载到return HtmlService.createHtmlOutputFromFile("Index").setXFrameOptionsMode( HtmlService.XFrameOptionsMode.ALLOWALL ) 中:

document.getElementsByTagName("form")[0].setattribute("target","Response")

document.addEventListener("submit",e => {
  const form = e.target
  
  const iframe = Object.assign(document.createElement("iframe"),{
    name: "Response"
  })
 
  document.body.innerHTML = iframe.innerHTML
  
  fetch(form.action,{
    method: form.method,body: new FormData(form)
  })
  
  e.preventDefault()
})

我想念什么?


这是我的表格:

<form action=https://script.google.com/macros/s/AKfycbzz-KveHder1A3CX8GcqZI6GR2MQj66PDRWNKoatIET_LXNqqs/exec method=post>  
  <fieldset>
    <legend>Select Foobar</legend>
    <label><input type=checkbox name=Foobar value=Foo>Foo</label>
    <label><input type=checkbox name=Foobar value=Bar>Bar</label>
    <label><input type=checkbox name=Foobar value=Baz>Baz</label>
  </fieldset> 
  <input type=submit value=Submit>
</form>
Google Sheet


表单提交到此Me

  

https://docs.google.com/spreadsheets/d/10VHS6bozcdNFYcRskkoONMT8Rt-2CwJ_LJGQWdkTJq4/


该Web应用程序具有Anyone,even anonymous执行权限和public downloadFile(key: any): Observable<string> { let newFileName = 'TestFile_username.CSV'; let s3 = new AWS.S3(); let downloadUrl = s3.getSignedUrl('getObject',{ Bucket: environment.bucket,Key: key,ResponseContentDisposition: 'attachment; filename ="' + newFileName + '"' }); console.log(downloadUrl); return of(downloadUrl); } 访问权限。

nuinuiweiwei 回答:通过Google Apps脚本提交表单时收到访问控制允许原错误 服务器端:Google Apps脚本

这个答案怎么样?

我认为您的问题是使用POST方法返回HtmlService.createHtmlOutputFromFile("Index")的值。

例如,作为解决方案,如何进行以下修改?

模式1:

在这种模式下,服务器端的脚本被修改。

服务器端:Google Apps脚本

function doPost(e) {

  // do something

  return ContentService.createTextOutput("ok");
}

注意:

  • 修改Web应用程序的脚本后,请重新部署Web应用程序为新版本。这样,最新脚本将反映到Web Apps。请注意这一点。

参考:

如果我误解了您的问题,而这不是您想要的方向,我深表歉意。

本文链接:https://www.f2er.com/3135245.html

大家都在问