Javascript 服务器端代码在google应用程序脚本中不起作用

Javascript 服务器端代码在google应用程序脚本中不起作用,javascript,jquery,html,google-apps-script,Javascript,Jquery,Html,Google Apps Script,嗨,我想做一件简单的事: 1) 当用户单击link1时,在我的HTML页面2)中创建两个链接-我希望它调用显示“Hello World”的服务器端函数。但当我点击link1时,我无法看到“Hello World”在任何地方显示。 我尝试过多次使用不同的变体来执行此操作,但都不起作用。提前谢谢 这是我的密码 代码.gs function doGet() { return HtmlService.createTemplateFromFile('IndexHTML').evaluate()

嗨,我想做一件简单的事: 1) 当用户单击link1时,在我的HTML页面2)中创建两个链接-我希望它调用显示“Hello World”的服务器端函数。但当我点击link1时,我无法看到“Hello World”在任何地方显示。 我尝试过多次使用不同的变体来执行此操作,但都不起作用。提前谢谢

这是我的密码

代码.gs

function doGet() {
  return HtmlService.createTemplateFromFile('IndexHTML').evaluate()
      .setTitle('Simple App')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function doSomething(){
   return ContentService.createTextOutput('Hello World');
}
IndexHTML.html

<!DOCTYPE html>
<html>
<head>
<?!= HtmlService.createHtmlOutputFromFile('Stylesheet').getContent(); ?>
</head>
<body>

<h1>Simple App</h1>
<p>
 Click on the buttons to view roles
</p>

<a href = "#" id = "index1" >I am index1</a>
    <a href = "#" id = "index2" >I am index2</a>

<?!= HtmlService.createHtmlOutputFromFile('JavaScript').getContent(); ?>

</body>
</html>

简单应用程序

单击按钮查看角色

JavaScript.html

<!-- Load the jQuery and jQuery UI libraries. -->
<script src="https://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.0/jquery-ui.min.js"></script>

<!-- Custom client-side JavaScript code. -->
<script>
$(document).ready(function() {
    $("#index1").click(function() {
       google.script.run.doSomething()     ;
}

    });
});
</script>

$(文档).ready(函数(){
$(“#index1”)。单击(函数(){
google.script.run.doSomething();
}
});
});
Stylesheet.html

<!-- Load the jQuery UI styles. -->
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />

<!-- Custom styles. -->
<style>
body
{
background-color:red;
}
</style>

身体
{
背景色:红色;
}
您没有看到任何地方显示“Hello World”,因为您没有编写任何代码来显示它

代码只需运行服务器端的
doSomething()
函数,该函数返回文本输出。您需要将成功处理程序添加到
google.script.run
,并指定在服务器端函数成功返回后运行的回调函数,例如:

google.script.run.withSuccessHandler(processResult).doSomething();
然后编写一个
processResult()
javascript函数,该函数接受服务器返回作为第一个参数,并执行您需要执行的任何操作,即:

function processResult(data) {
  console.log(data);
}
有关更多详细信息,请参阅和