【问题标题】:Script function not found doget, but I don't use doGet on my code找不到脚本函数 doget,但我没有在我的代码上使用 doGet
【发布时间】:2019-02-08 21:51:21
【问题描述】:

我正在使用电子表格作为存储进行 PWA。当我想提交我的信息时,它在 Web(Chrome、Safari、Opera 等)上运行良好,它也像 Android 上的 PWA 一样运行。

但是当我在 Iphone/iPad 上添加应用程序时,当我尝试提交信息时,它会在 safari 上打开一个页面并向我显示此错误:

找不到脚本函数:doGet。

谷歌脚本

    // spit out all the keys/values from the form in HTML for email
    // uses an array of keys if provided or the object to determine field order
    function formatMailBody(obj, order) {
    return result; // once the looping is done, `result` will be one long string to put in the email body
    }

    function doPost(e) {
    //operations with values from form
    record_data(e);}

    function record_data(e) {//operations}

这是我的 HTML 代码:

    <form id="gform" class="pure-form pure-form-stacked" data-email="xxxxx@gmail.com" action="https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxx/exec" method="POST">
    //Some inputs

    <input type="hidden" id="de" name="de" value='nombre'> 
    <input type="hidden" id="tipopersona" name="tipopersona"> 
    <input type="hidden" id="correo" name="correo" > 
    </form>

我想删除 doGet () 错误并按应有的方式执行其他代码,否则只知道在 iOS PWA 中导致该错误的原因。

【问题讨论】:

    标签: ios web safari progressive-web-apps


    【解决方案1】:

    此问题已在先前的 Stack Overflow 主题中得到解答,标题为:Script function not found: doGet。该答案未显示问题解决方案的代码,因此我将在此处添加,以防其他人遇到此问题。

    正如该答案中所共享的,无论脚本是否处理 GET 请求,所有 Google Apps 脚本网络应用程序部署都必须包含 doGet 函数。我通过添加 doGet 函数重写脚本并将其返回值设置为 doPost 函数并传递给它的事件参数来消除此错误。下面是一个简化的例子:

    function doPost (e) {
    
        Logger.log(`POST method activated: ${e}`);   
    
        return ContentService.createTextOutput(JSON.stringify('doPost is working.'));
    }
    
    function doGet (e) {
    
        return doPost(e);    
    }
    

    当前用于 web 应用程序的Google Apps Script documentation 似乎没有提到这个要求,但是当 doGet 被添加到 doPost 脚本时,它将消除这个特定的错误。

    【讨论】:

      猜你喜欢
      • 2020-11-22
      • 2015-09-30
      • 1970-01-01
      • 2020-01-06
      • 1970-01-01
      • 2020-06-20
      • 2016-12-14
      • 1970-01-01
      • 2018-01-21
      相关资源
      最近更新 更多