首页 > 解决方案 > 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>


标签: google-apps-scriptgoogle-sheets

解决方案


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.


推荐阅读