使用HtmlService在Google Apps脚本中执行POST吗?

时间:2013-09-03 06:30:36

标签: google-apps-script

我正在尝试使用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, “参数”:{} “的contextPath”: “”, “参数”:{}, “CONTENTLENGTH”:0}

我期待表单将数据返回给我,以便我可以使用后续页面中的数据。我想知道这是否与Caja中毒有关。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

由于Google Caja.

施加的安全限制,发布本身在HtmlService中不起作用

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