【问题标题】:Do Form POST in Google Apps Script with HtmlService?使用 HtmlService 在 Google Apps 脚本中进行表单 POST?
【发布时间】:2013-09-06 07:02:12
【问题描述】:

我正在尝试使用 Google Apps 脚本创建一个向导类型的应用程序。由于使用 UiApp 进行样式设计在后方非常痛苦,因此我正在尝试使用 HtmlService 路线。我无法让表单 POST 工作。这是我的示例代码:

// Code.gs
function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('p1');
}

function doPost(e) {
  var params = Utilities.jsonStringify(e);
  var page = HtmlService.createTemplateFromFile('p2');
  page.params = params;
  return page.evaluate().setSandboxMode(HtmlService.SandboxMode.NATIVE);
}

p1.html

<div>
  <form action="#" method="post">
    <input type="text" id="myContents"></input>
    <input type="submit" value="Submit"></input>
  </form>
</div>

p2.html

<div>
  <?=params?>
</div>

我在 p1 上单击“提交”得到的输出是

{"queryString":null,"parameter":{},"contextPath":"","parameters":{},"contentLength":0}

我希望表单能够将数据返回给我,以便我可以在后续页面中使用这些数据。我想知道这是否与卡哈中毒有关。有什么想法吗?

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    由于Google Caja. 施加的安全限制,发布本身在 HtmlService 中不起作用

    在 HtmlService 中执行“表单发布”的正确方法是使用 google.script.run 语法在客户端上下文中调用服务器端函数。有关详细示例,请参见此处 - https://developers.google.com/apps-script/guides/html-service-communication#forms

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-18
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多