将请求发送到数据库(Google表)



我在Google表中创建了一个脚本。它从我的表格中的桌子(Kinda数据库)中得出了一个单元格的结果。我希望结果将结果发送到我的HTML页面,并且我已经尝试使用XMLHTTPRequest尝试了。

没有成功。

我做错了什么?

这是脚本

<script>
function load() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "https://script.google.com/macros/s/AKfycby5RzvUWSEOjerJpouxN72wpsgpsF8IWQo2AvjZUdRPcqskz28/exec", true);
  xhttp.send();
}
</script>
<html>
<body>
<h1>Members:</h1>
<button type="button" onclick="load()">Request data</button>
<p id="demo"></p>
</body>
</html>

读取Google的电子表格:

  • 下载一个名为tabletop的脚本,然后将其添加到您的HTML中。(读书人在这里)
  • 在Google文档中,请转到File菜单,然后选择Publish to the web。然后单击Start publishing。将出现一个URL,例如https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE&output=html,即您将使用的URL。
  • 然后将其称为:

<script type="text/javascript">
  var public_spreadshseet_url = 'https://docs.google.com/spreadsheet/pub?YOUR_URL_HERE';
  
  // YOUR_URL_HERE sample: hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE&output=html
  // You get this URL from google docs after you publish the spreadsheet
  function init() 
  {
      Tabletop.init(
      { 
          key: public_spreadshseet_url,
          callback: showInfo,
          simpleSheet: true
      })
  }
  
  // This function gets called to give output
  function showInfo(data)
  {
      alert("Successfully processed!")
      console.log(data);           <-- Here is the spreadsheet data
  }  
</script>
<html>
<body>
<h1>Members:</h1>
<button type="button" onclick="init()">Request data</button>
<p id="demo"></p>
</body>
</html>

相关内容

最新更新