जावा स्क्रिप्ट परिणाम HTML में नहीं दिख रहा है
Nov 30 2020
मैंने यह जांचने के लिए एक जीएएस कोड लिखा था कि कर्मचारी अंदर है या नहीं (Google शीट से डेटा निकाल रहा है)। कंसोल लॉग मुझे सही उत्तर देता है लेकिन जब मैं बटन पर क्लिक करता हूं तो उत्तर सामने के छोर पर दिखाई नहीं देता है। क्या आप मेरी मदद कर सकते हैं कि मैं कहाँ गलत हुआ?
<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>
जवाब
4 Diego Nov 30 2020 at 10:49
Google एक बहुत अच्छा क्लाइंट-टू-सर्वर संचार मार्गदर्शिका प्रदान करता है जो मैं आपको सुझाव देता हूं कि यह कैसे काम करता है इसकी बेहतर समझ प्राप्त करने के लिए आप पढ़ें।
आप अपनी स्क्रिप्ट स्क्रिप्ट में ऐप्स स्क्रिप्ट कोड (जैसे SpreadsheetApp.getActiveSpreadsheet()
) नहीं डाल सकते हैं। उस कोड को बैकएंड में एप्स स्क्रिप्ट सर्वर द्वारा चलाया जाना चाहिए और फिर आप कॉल का उपयोग करके इसे कॉल करेंगे google.script.run।
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>