小编Joo*_*aal的帖子

如何在我的谷歌脚本中允许 CORS 请求?

我想将我的联系表格发布到我的 google 脚本,该脚本将向我发送电子邮件。我使用以下代码:

var TO_ADDRESS = "example@gmail.com"; // where to send form data

function doPost(e) {

  var callback = e.parameter.callback;

  try {
    Logger.log(e); // the Google Script version of console.log
    MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
                      JSON.stringify(e.parameters));
    // return json success results
    return ContentService
          .createTextOutput(callback+
          JSON.stringify({"result":"success",
                          "data": JSON.stringify(e.parameters) }))
          .setMimeType(ContentService.MimeType.JSON);
  } catch(error) { // if error return this
    Logger.log(error);
    return ContentService
          .createTextOutput(callback+JSON.stringify({"result":"error", 
          "error": e}))
          .setMimeType(ContentService.MimeType.JSON);
  }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试发布到 google 脚本 url 时,出现以下错误:

CORS 政策已阻止在 ' https://script.google.com/macros/s/~~myscriptid~~/exec ' 从源 ' http://localhost:4200 '访问 XMLHttpRequest …

cors google-apps-script

5
推荐指数
4
解决办法
9850
查看次数

标签 统计

cors ×1

google-apps-script ×1