HTML服务提交表单未调用google

HTML服务提交表单未调用google

本文介绍了HTML服务提交表单未调用google.script.run函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以前可以正常运行的脚本,但是突然停止了工作.

I have a script that used to work just fine, but has suddenly stopped working.

用户从用户创建的菜单中选择一个选项,该菜单将启动一个对话框(HTML服务表单)以收集两个参数.一切都很好.

The user selects an option from a user-created menu, which launches a dialog box (HTML Service form) to collect two parameters. This is all working fine.

用户提交表单时,应执行此代码.

When the users submits the form, this code should execute.

<input type="submit" value="Submit" class="submit" onclick =
"google.script.run.withSuccessHandler(google.script.host.close())
.createAgenda(this.parentNode)"/>

窗体正在关闭(google.script.host.close()有效),但是没有调用createAgenda函数.

The form is closing (google.script.host.close() works), but the createAgenda function is not being called.

推荐答案

withSuccessHandler()(和withFailureHandler())的参数应该是一个回调函数.您提供的不是功能:google.script.host.close().由于已包含括号,因此先执行close(),以获得withSuccessHandler()的返回值.这将关闭对话框,并停止客户端JavaScript.

The parameter for withSuccessHandler() (and withFailureHandler()) is supposed to be a callback function. You've provided something that isn't a function: google.script.host.close(). Since you've included the parentheses, close() gets executed first, to obtain a return value for withSuccessHandler(). That closes the dialog, and halts the client-side JavaScript.

您只需要删除括号即可,仅按名称引用该函数:

You just need to remove the parentheses, referring to the function by name only:

<input type="submit" value="Submit" class="submit"
 onclick="google.script.run
                       .withSuccessHandler(google.script.host.close)
                       .createAgenda(this.parentNode)"/>

这篇关于HTML服务提交表单未调用google.script.run函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:33