google-apps-script - GoogleSheets google.script.run 总是去 FailureHandler
问题描述
我正在使用 GoogleSheets HTMLService。我从我的 Html 页面的脚本中调用 google.script.run。但它总是去FailureHandler。它有什么问题?请看下面的代码。当我运行它时,它总是显示警报失败。此外,记录器没有显示任何错误。它也没有在 hello() 函数中显示控制台日志“Inside Hello”。我们是否还需要做一些浏览器设置(我使用的是 chrome - 允许使用 javascript)。
[更新] 用 console.log 替换 Logger.log 后,我将其视为传输错误。
modeDialog.gs
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile("test");
html.setWidth(90).setHeight(1);
var ui = SpreadsheetApp.getUi().showModalDialog(html, "Opening ..." );
}
function hello() {
console.log("Inside Hello");
return "hello";
}
test.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onSuccess(str) {
window.alert("executed");
}
function onFailure(error) {
window.alert("failed");
Logger.log(error);
}
google.script.run.withSuccessHandler(onSuccess).withFailureHandler(onFailure).hello();
</script>
</head>
<body>
<div id="failureContent"></div>
Hello world
</body>
</html>
解决方案
As I mentioned that it was working earlier in Chrome and is currently working in FireFox, I tested it again after changing my chrome settings to default by going to Chrome > Settings > Advanced > Reset and clean up > Restore settings to their original defaults.
It is working fine after that. So setting this as the answer.
推荐阅读
- python - pandas - 获得多个最大值
- mysql - mysql查询可以在哪里进行限制吗?
- git - `git fetch` 和 `git push` 用于本地快速转发的区别
- matlab - 特定空间模式中的细胞集落存活映射
- discord.js - 如何通过名称获取类别 ID?
- python - tkinter python - 菜单按钮不适用于循环
- python - 单击按钮时显示图像 Python GUI
- python - Python numpy:索引20超出轴0的范围,大小为20?
- swagger - 在 WebDeploy 之后无法访问 Swagger UI
- session - 在 NextJS getServerSideProps 中使用 Bearer 令牌装饰 api 请求