我正在尝试使用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中毒有关。有什么想法吗?
答案 0 :(得分:2)
在HtmlService中执行“表单帖子”的正确方法是使用google.script.run
语法通过客户端上下文调用服务器端函数。有关详细示例,请参阅此处 - https://developers.google.com/apps-script/guides/html-service-communication#forms