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' />
And for my JS:
function formSubmit(){
//verify inputs
//if inputs are good
google.script.run.withSuccessHandler(success).withFailureHandler(fail).submit(document.forms[0]);
}
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;
});
}
*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.
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 ("server side")
ui.html ("client side")
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).