2

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

9 Comments

I get positive results when running simpler script processes. The script takes a GmailLabel, and processes it doing various things. If the label is relatively small, it works as desired. If it has 300+ messages - then I see the errors (intermittently, more often than not). You can view the source here and the script in action here.
Also, I built a interface using UiApp and it behaves the same way. The script worked as desired up until a couple of weeks ago. Previous working versions also behave like this now when I restore them. I can successfully run the script from the editor by creating a function that calls the clickHandler function and passes it the params manually.
Greg - roughly, how long before your operation re-tries? Can you look at the Chrome Dev Tools to see if a new HTTP call is being made? See info here - developers.google.com/chrome-developer-tools/docs/network
After trying a few scenarios, nothing in the Network profiler or the console indicates that it is making a new call. Based on the output the script makes in my Drive, it seems to be about every 1.5 - 2 minutes.
Greg, if there is a new called made in HtmlService, there HAS to be something in the Network profiler as its made over HTTP. I was finally able to see something when I added a 3-4 minute delay and I re-ran once. This is not the same as the UiApp retry issue as they are very different.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.