0% found this document useful (0 votes)
31 views2 pages

15.1 Lesson 8 Source

The document loads posts data from a Google Sheet using Google Apps Script and displays it on a web page. It uses JavaScript to make requests to the server script and parse the JSON response containing the post data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

15.1 Lesson 8 Source

The document loads posts data from a Google Sheet using Google Apps Script and displays it on a web page. It uses JavaScript to make requests to the server script and parse the JSON response containing the post data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

<script>

var datags = <?!= JSON.stringify(data) ?>;


console.log(datags);
</script>
<!DOCTYPE html>
<html>

<head>
<base target="_top"> </head>

<body>
<div>
<input type="button" class="btn1" value="Load Posts"> </div>
<script>
document.addEventListener('DOMContentLoaded', init);
document.querySelector('.btn1').addEventListener('click', getPostOutput,
false);

function getPostOutput() {
console.log('clicked');
google.script.run.withSuccessHandler(buildPosts).getPosts();
}

function buildPosts(data) {
let d = JSON.parse(data);
console.log(d);
}

function init() {
console.log('page ready');
}
</script>
</body>

</html>

*****GS*****
function doGet() {
//var html = HtmlService.createHtmlOutputFromFile('index');
var html = HtmlService.createTemplateFromFile('index');
html.data = {
email: Session.getActiveUser().getEmail()
}
var output = html.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
return output;
}

function test1() {
Logger.log(getPosts());
}

function getPosts() {
var ss =
SpreadsheetApp.openById('1_nGL6C5Ge6F7FrdSd96mgf9U_ehNPxXfH40atjcdg0c');
var sheet = ss.getSheetByName('posts');
var rows = sheet.getDataRange().getValues();
var posts = rows.slice(1);
var json = JSON.stringify(posts);
return json;
}
//function doSomething() {
// Logger.log('I was called!');
//}
function lesson4() { //should be doGet
var html = HtmlService.createHtmlOutput("hello world 2");
return html;
}

function lesson3() {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(['Hello', 'World', 5000, sheet.getName()]);
Logger.log(sheet.getName());
}

You might also like