2021年1月4日星期一

How can I select on doGet(e) function between HtmlService and ContentService from HTML form?

I'm trying to select a working mode on doGet(e) on my Google Script App when a function on the HTML form finish but I not sure how can I do it. The Google Script App is already embed with IFRAME on my webpage and from the webpage I make a callback to Google Script with a JSONP and works perfect but I need to make the call with a setinterval to get the response from the Google Script only when the HTML finish. It is the only way I think I can receive de response from Google Scrip. On Google.gs now works with a conditional to return between HtmlService or ContentService if I call it, but I want allow only the ContentService when the function showSuccess() run from the HTML. How can I do it? Thanks you.

CallBack from my Webpage to change a h1 (like an example):

var refreshCall = setInterval(test, 1000);    function test() {  $.getJSON('https://script.google.com/macros/s/SCRIPT_ID/exec?prefix=?', null, function (results) {      $('h1').html(results);                  });  }  

Google.gs:

function doGet(e) { //HOW SHOULD I CHANGE THIS TO RETURN ONLY ContentService WHEN THE FUNCTION " showSuccess()" ON "forms.html" ALLOW IT    if (e.parameter.prefix){      var result = 'Hello World';      var content = e.parameters.prefix + '(' +JSON.stringify(result) + ')';            return ContentService.createTextOutput(content)      .setMimeType(ContentService.MimeType.JAVASCRIPT);    }    else {      var html = HtmlService.createHtmlOutputFromFile('forms');      return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);    }  }  

forms.html on Google Script App project

<script>      function showSuccess() {      //HERE IS WHERE I NEED TO CALL doGet(e) TO ALLOW ONLY ContentService            }  </script>  

EDIT:

JSFIDDLE

I create a JSFIDDLE to explain better with an example but with a button instead of a interval. If you click on the Run "showSuccess()" a DONE text appear to show the execution of the function on the HTML from GAS project. If you click on GET DATA button, the title TO CHANGE change to STACKOVERFLOW always. I need that 'GET DATA' button only works when the DONE appear. This is the Script Project Example PROJECT

https://stackoverflow.com/questions/65550935/how-can-i-select-on-dogete-function-between-htmlservice-and-contentservice-fro January 03, 2021 at 10:28PM

没有评论:

发表评论