我应该如何使用HTML代码从Google表格中获取数据

问题描述 投票:0回答:1

我正在尝试使用Phonegap制作移动应用。我正在使用HTML编写代码,以在Google表格中搜索ID,并提供完整的行作为回报。以下是我的HTML代码。

    <!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  </head>
  <body>
     <div class="form-row">
      <div class="form-group col-md-2">  
        <label for="idNum">ID Number</label>
        <input type="text" class="form-control" id="idNum">
        <output id="rnum"></output>
      </div>
     <button type="button" class="btn btn-outline-info" id="searchbtn" onclick="search_ID()">Search Profile</button>
   </div>
 <p id="demo"></p>
 <form class="google_script" method="POST"  
 action="https://script.google.com/macros/s/AKfycbwlHuXwW1fEDfeer1ot6Ltb9cqT83VRZfQQQdTqZSgPvpYapUs/exec">

 <script data-cfasync="false" src="index.js"></script>

   </body>
</html>

和index.js文件是:

function search_ID() {
    var input = document.getElementById("idNum").value;

    if (isNaN(input)) {
    voteable = "Input is not a number";
      } else {
    voteable = (input.length ==6 ) ? "Correct Value" : "Wrong Value";
  }
  document.getElementById("demo").innerHTML = voteable;
    google.script.run.doSomething();
}   

我想从本地HTML文件调用Google Script中的函数,以从Google表格中获取数据(以公开视图为准)。请帮助。

javascript html android-studio google-apps-script phonegap-plugins
1个回答
0
投票

我认为您想做这样的事情:

function search_ID() {
  var input = document.getElementById("idNum").value;

  if (isNaN(input)) {
    voteable = "Input is not a number";
  } else {
    voteable = (input.length ==6 ) ? "Correct Value" : "Wrong Value";
  }
  document.getElementById("demo").innerHTML = voteable;
  google.script.run.
  .witSuccessHandler(function(obj){
    window.alert(obj.msg);
  })
  doSomething();
}   

gs:

function doSomething() {
  //
  return {msg:"I did something and returned;"}
}

client to server communication

© www.soinside.com 2019 - 2024. All rights reserved.