google.script.run.withSuccessHandler()造成问题 [英] google.script.run.withSuccessHandler() creating problems

查看:76
本文介绍了google.script.run.withSuccessHandler()造成问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HtmlService向我的脚本提交一个简单的表单以进行处理.我正在使用jQuery进行输入验证之类的操作.我为提交按钮创建了一个表单和一个formSubmit()函数:

I'm using HtmlService to submit a simple form to my script for processing. I'm using jQuery to do things like input validation. I created a form and a formSubmit() function for my submit button:

<input type='button' onclick='formSubmit()' value='Submit' />

对于我的JS:

function formSubmit(){
   //verify inputs
   //if inputs are good
   google.script.run.withSuccessHandler(success).withFailureHandler(fail).submit(document.forms[0]);
}

我已将问题隔离到withSuccessHandler(),它只是在几天前才开始发生.如果存在,它将一遍又一遍地调用我的脚本.有时每隔1分钟间隔一次,有时每2-3分钟间隔一次.停止执行的唯一方法是关闭浏览器窗口.这是success()函数:

I have isolated the problem to withSuccessHandler() and it only started happening a few days ago. When this is present, it calls my script over and over again. Sometimes in 1 minute intervals, sometimes every 2-3 minutes. The only way to stop the execution is to close the browser window. Here is the success() function:

function success(e){
  $('#dialog-body').html(e.body);
  $('#loading').fadeOut(100, function (){
    $('#btnSubmit').fadeIn(100);
    $('#dialog').dialog( "open");
    $('#txtEmail').val("");
    document.getElementById('txtEmail').disabled=true;
    document.getElementById('chkEmail').checked=false;
    document.getElementById('chkShare').checked=false;
  });
}

*更新:经过一段时间的测试,我什至不能确定它只是.withSuccessHandler()-似乎是我完全可以使用google.script.run服务的任何时候.问题是断断续续的.我尝试了其他运行脚本的方法,它们都可以正常工作.

*Update: After testing this for a while longer, I can't even be sure it is just .withSuccessHandler() - it seems to be anytime I use the google.script.run service at all. The problem is intermittent. I have tried other methods of running the script and they all work fine.

推荐答案

我看不到此问题.我已经编写了一个可以完美运行的小应用程序.也许在客户端代码的其他地方,有一个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).

这篇关于google.script.run.withSuccessHandler()造成问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆