Greg
Greg

Reputation: 737

google.script.run.withSuccessHandler() creating problems

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.

Upvotes: 2

Views: 7146

Answers (1)

Arun Nagarajan
Arun Nagarajan

Reputation: 5645

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")

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

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

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>

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).

Upvotes: 1

Related Questions