且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

google.script.run.withSuccessHandler()造成问题

更新时间:2023-02-24 10:00:55

我看不到此问题.我已经编写了一个可以完美运行的小应用程序.也许在客户端代码的其他地方,有一个setTimeout或其他循环在起作用?

I am unable to see this issue. I've written a small app that works perfectly. Perhaps somewhere else in your client side code there is a setTimeout or some other loop that is kicking in?

Code.gs(服务器端")

Code.gs ("server side")

function submit(e) {return 'Recieved ' + e.simpleTextField;}

function doGet(){return HtmlService.createHtmlOutputFromFile('ui');}

ui.html(客户端")

ui.html ("client side")

<html>
<script>
function formSubmit(){
   google.script.run.withSuccessHandler(success).withFailureHandler(fail).submit(document.forms[0]);
}
function success(e){alert(e);}
function fail(e){console.log(e);}
</script>
<body><form>
<input type='text' name='simpleTextField' />
<input type='button' onclick='formSubmit()' value='Submit' />
</form></body>
</html>

这很好,我只看到一个弹出窗口.如果success被多次调用,那么我会看到多个弹出窗口,但没有看到.

This works fine and I only see one popup ever displayed. If success gets called multiple times, then I would see multiple popups which I dont see.

这是应用程序正在使用,这里是源代码(仅查看).

Here is the app in action and here is the source code (view-only).