Java Script Sonuçları HTML'de gösterilmiyor

Nov 30 2020

Ben çalışan olup olmadığını kontrol etmek bir GAZ kodunu yazdığı In or Not (Google sayfalarında veri ayıklama) içinde. Konsol günlüğü bana doğru cevabı veriyor ancak düğmeye tıkladığımda cevap ön uçta görünmüyor. Nerede yanlış yaptığımı gidermeme yardım edebilir misin?

<div>
<script>
 function onStatus(notify) { 
 
 var employee = "John Peter";
 
 var ss = SpreadsheetApp.getActiveSpreadsheet();        
 var mainSheet = ss.getSheetByName("MAIN");
 var data = mainSheet.getDataRange().getValues();
 
 
   for (var j = 0; j < data.length; j++){
    var row = data[j];
    var mainSheet2 = row[4];
    var mainSheet3 = row[0];
    var status = (mainSheet2 =="IN" && mainSheet3 == employee) ; 
    if (status == true){
      var notify = employee +" You Are In"
      
      return notify;
 
  }
      }
document.getElementById('status').innerHTML= notify;       
      }
     
    </script>
<button onclick="onStatus()">Check Status</button>

 <font color='Green' id="status" ></font>
</div>

Yanıtlar

4 Diego Nov 30 2020 at 10:49

Google, bunun nasıl çalıştığını daha iyi anlamak için okumanızı şiddetle tavsiye ettiğim çok iyi bir İstemciden Sunucuya İletişim kılavuzu sağlar .

Ön SpreadsheetApp.getActiveSpreadsheet()uç komut dosyalarınıza uygulama komut dosyası kodu (ör. ) Koyamazsınız. Bu kodun arka uçtaki apps komut dosyası sunucusu tarafından çalıştırılması gerekir ve ardından bir arama kullanarak onu google.script.runçağırırsınız.

Code.gs

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('Index');
}

function checkStatus() { 
  var employee = "John Peter";
  var ss = SpreadsheetApp.getActiveSpreadsheet();        
  var mainSheet = ss.getSheetByName("MAIN");
  var data = mainSheet.getDataRange().getValues();
  
  for (var j = 0; j < data.length; j++){
    var row = data[j];
    var mainSheet2 = row[4];
    var mainSheet3 = row[0];
    var status = (mainSheet2 =="IN" && mainSheet3 == employee) ; 
    if (status == true){
      return employee + " You Are In";
    }
  }
}

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <div>
      <button onclick="onStatus()">Check Status</button>
      <font color='Green' id="status" ></font>
    </div>

    <script>
      function onStatus() {
        google.script.run
          .withSuccessHandler(updateStatus) // Send the backend result to updateStatus()
          .checkStatus(); // Call the backend function
      }
  
      function updateStatus(notify) {
        document.getElementById('status').innerHTML= notify;
      }
    </script>
  </body>
</html>