gpt4 book ai didi

javascript - GAS .withSuccessHandler 失败并出现错误

转载 作者:行者123 更新时间:2023-12-01 04:03:23 25 4
gpt4 key购买 nike

我编写了一个 Google Sheets 插件,它使用模式对话框作为界面。我在运行成功处理程序时遇到问题,因此我创建了一个框架接口(interface)进行测试,但也遇到了同样的问题。

每当服务器端函数返回时,成功处理程序中指定的函数就应该运行。相反,它会抛出错误“Untaught TypeError:a 不是函数”。我可以通过按钮手动触发为处理程序指定的函数(仅为演示目的添加。代码如下:

<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>

function success(){
document.getElementById("waitMessage").innerHTML = "TEST";
}

function testFunc(){
google.script.run.withSuccessHandler("success").serverSideFunc();
}

</script>
</head>
<body>
<p>
Click the button to close the window
</p>
<form>
//Doesn't work
<input type="button" name="test" value="Server-side test" onclick="testFunc()">
//Works
<input type="button" name="test-client" value="Client-side test" onclick="success()">
</form>
<div id="waitMessage">
<p></p>
</div>
</body>
</html>

下面的.gs脚本文件:

function serverSideFunc(){
Logger.log("");
}

如您所见,脚本文件只是一个旨在触发成功处理程序的虚拟函数。

这是怎么回事?我错过了一些简单的事情吗?

最佳答案

您没有返回错误。您不要在要运行的函数名称两边加引号:

function testFunc(){
google.script.run.withSuccessHandler(success).serverSideFunc();
}

关于javascript - GAS .withSuccessHandler 失败并出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42007664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com