AJAX post to google spreadsheet

后端 未结 3 942
余生分开走
余生分开走 2020-12-04 09:53

I am attempting to post form data to a google spreadsheet. Currently, if the form is validated, then the following occurs:

if (validateForm === true) {
              


        
3条回答
  •  有刺的猬
    2020-12-04 10:34

    I will show you the EASY WAY to send data to a Google SpreadSheet without AJAX neither Google Form, or PHP...just Google SpreadSheet and HTML or even Android.

    1. Create a new Google SpreadSheet.
    2. Open Tools/script editor

    You just need two files in the editor a HTML and a Code.gs:

    as an example:

    1. Go to File/new HTML name this file=Index.html:

      
      
      
      
      
      
      
      
      
      Prueba de Envio de informacion



    there are 3 fields to send: EMAIL, CEDULA, NOMBRE

    1. In the same ScriptEditor go to de Code.gs file and type:

      function doGet() {
      return HtmlService.createHtmlOutputFromFile('Index')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
      }
      
      function doSomething(s1,s2,s3){
      
      Logger.log('datos:'+s1+"  "+s2+"  "+s3);
      var enlace="https://docs.google.com/spreadsheets/d/
      1XuAXmUeGz2Ffr11R8YZNihLE_HSck9Hf_mRtFSXjWGw/edit";
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var ss = SpreadsheetApp.openByUrl(enlace);
      var sheet = ss.getSheets()[0];
      sheet.appendRow([s1, s2, s3]);
      Logger.log(ss.getName());
      }
      

    where enlace is the url of your SpreadSheet

    1. Publish as Application App and get the url of your new Script. Now you can use this url as embed in your HTML application or android app. That's it. The user will be asked for permission to open this script

提交回复
热议问题