简体   繁体   中英

GAS .withSuccessHandler fails with error

I have written a Google Sheets add-on that uses a modal dialog as the interface. I was having trouble getting the success handler to run, so I created a skeleton interface for testing, and have the same issue.

Whenever the server-side function returns, the function specified in the success handler should run. Instead, it throws an error "Untaught TypeError: a is not a function". I am able to manually trigger the function specified for the handler via a button (added for demonstration purposes only. Code below:

<!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 script file below:

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

As you can see, the script file is just a dummy function designed to trigger the success handler.

What's going on here? Have I missed something simple?

You are not having an error returned. You do not put quotes around the function name to run:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM