如何将 code.gs 中的内容返回到 index.html。
我在“Index.html”中尝试过此操作,但这不起作用。
index.html
$('#test').click(function() {
alert(google.script.run.getAmountOfImages());
});
代码.gs
function getAmountOfImages()
{
return "Tom"
}
请帮忙。
最佳答案
"google.script.run is an asynchronous client-side JavaScript API available in HTML-service pages that can call server-side Apps Script functions."
因此您的结果将在回调中返回。因此,您必须使用处理程序函数,即 withFailureHandler
和 withSuccessHandler
google.script.run
.withFailureHandler(function(err){
console.error("error occured", e);
})
.withSuccessHandler(function(res){
alert(res);
})
.getAmountOfImages();
res
成功处理程序回调函数中的参数将保存来自 Google 应用脚本的响应。
关于javascript - Google脚本从code.gs返回到index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36304114/