google-apps-script - google.script.run 函数不会生成 Logger.log
问题描述
我正在尝试复制一个简单的 Web 应用教程视频,但无法让 google.script.run.function 在我的 code.gs 中创建日志。这是我的代码:
代码.gs
function doGet(){
return HtmlService.createHtmlOutputFromFile("clock");
}
function userClicked(){
Logger.log("Log clicked");
console.log("Console click");
}
时钟.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>test</h1>
<div id="replace">___</div>
<button id="submit">Submit</button>
<script>
document.getElementById("submit").addEventListener("click",doSubmit);
function doSubmit(){
google.script.run.userClicked();
document.getElementById("replace").innerHTML = "clicked";
}
</script>
</body>
</html>
当我在编辑器中运行 userClicked 时,执行日志显示得很好。此外,当在 web 应用程序中单击按钮时,“单击”文本显示得很好。此外,doGet 和 userClicked 都出现在我的 Executions 中。问题是从 webapp 运行时日志不会显示在我的执行日志中。我发现了一些与此类似的线程,但似乎从未得到解决。
更新:我也尝试添加 withSuccessHandler 并且结果是相同的 - 函数都在执行中运行良好,但没有日志显示在执行日志中(如果我在旧版本中测试,“日志”也是如此)。新的html是这样的:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>test</h1>
<div id="replace">___</div>
<button id="submit">Submit</button>
<script>
document.getElementById("submit").addEventListener("click",doSubmit);
function onSuccess(){
document.getElementById("replace").innerHTML = "success";
}
function doSubmit(){
google.script.run.withSuccessHandler(onSuccess).userClicked();
}
</script>
</body>
</html>
解决方案
那么有效的是,如果您创建一个函数并使用您的服务器函数调用该函数,那么:
function logHi(){
console.log("hi")
}
// And then use it
function userClicked(){
logHi()
}
推荐阅读
- c# - 是否可以使用 C# 程序获取安装在给定 PC 上的 PDF 阅读器列表?
- java - Java 8 流按最大重复排序,然后是不同的
- html - **[已解决]** 在移动设备上运行网站时图像大小混乱
- c# - 如何在使用 Windows 应用程序驱动程序的 UI 自动化单元测试期间验证 WPF 复选框的状态?
- python - 1:1 Python 请求响应
- reactjs - 脚本资源位于重定向后面,这是不允许的。firebase 云消息传递
- java - 构建一个匹配 3 个点的变换的 AffineTransform 对象
- azure-devops - Azure DevOps 中基本和 Visual Studio 专业订阅访问级别之间的差异
- node.js - 关系中的 TypeORM OneToMany 过滤器不影响结果
- javascript - 一个或可选的多个函数作为函数参数