Google脚本从code.gs返回到index.html [英] Google script return from code.gs to index.html
问题描述
如何将code.gs中的内容返回到index.html。
How can I return something from code.gs to index.html.
我在Index.html中尝试过此操作,但这不起作用。
I have tried this in "Index.html", but this doesn't work.
index.html
$('#test').click(function() {
alert(google.script.run.getAmountOfImages());
});
Code.gs
function getAmountOfImages()
{
return "Tom"
}
请帮忙。
推荐答案
根据文档
google.script.run是HTML服务页面中可用的异步客户端JavaScript API
,可以调用服务器端的Apps脚本
函数。
"google.script.run is an asynchronous client-side JavaScript API available in HTML-service pages that can call server-side Apps Script functions."
因此您的结果将在回调中返回。所以你必须使用Handler函数,即 withFailureHandler
和 withSuccessHandler
therefore your result will be returned in a callback. So you will have to use Handler functions i.e withFailureHandler
and withSuccessHandler
google.script.run
.withFailureHandler(function(err){
console.error("error occured", e);
})
.withSuccessHandler(function(res){
alert(res);
})
.getAmountOfImages();
res
成功处理程序回调函数中的参数将保持谷歌应用程序脚本的响应。
res
Parameter in success handler callback function will hold the response from google app script.
这篇关于Google脚本从code.gs返回到index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!