你如何运行一个服务器端的功能,而在客户端?
How do you run a function of the server side while on the client side?
这个问题困扰我好几天了。我正在尝试将数据传递到我的服务器端脚本,但是当我这样做时,我收到了这条错误消息。
Error Message
我试过在 youtube 上观看几个视频,它们都说同样的话,你必须使用 google.script.run。问题来自于 运行 之后调用的函数。这是我使用的代码示例。
function doGet() {
var output = HtmlService.createTemplateFromFile("index");
output.content = "New string being passed";
return output.evaluate();
}
function doUpload(data){
logger.log(data);
Logger.log("I was called!")
}
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><?= content ?></title>
</head>
<body>
<h1><?= content ?></h1>
<div id="output"></div>
<form>
<input type="type" name="first" id="first" value="Laurence">
<input type="button" id="subButton" value="submit">
</form>
<script>
var output = document.getElementById("output");
var first = document.getElementById("first");
document.getElementById("subButton").addEventListener("click", function(e){
e.preventDefault();
output.innerHTML = first.value;
var myData ={"first":first.value};
console.log("hello");
google.script.run.doUpload(myData);
})
</script>
</body>
</html>
如您所见,我正在尝试 运行 执行上传(数据),但不会 运行。我已经把我所有的帐户都烧掉了,因为我认为这可能是问题所在,但事实并非如此。请帮忙,谢谢!
它对我有用:
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><?= content ?></title>
</head>
<body>
<h1><?= content ?></h1>
<div id="output"></div>
<form>
<input type="type" name="first" id="first" value="Laurence">
<input type="button" id="subButton" value="submit">
</form>
<script>
window.onload=function() {
var output = document.getElementById("output");
var first = document.getElementById("first");
document.getElementById("subButton").addEventListener("click", function(e){
e.preventDefault();
output.innerHTML = first.value;
var myData ={"first":first.value};
console.log("hello");
google.script.run.doUpload(myData);
});
}
</script>
</body>
</html>
检查你的view/executions
这个问题困扰我好几天了。我正在尝试将数据传递到我的服务器端脚本,但是当我这样做时,我收到了这条错误消息。 Error Message
我试过在 youtube 上观看几个视频,它们都说同样的话,你必须使用 google.script.run。问题来自于 运行 之后调用的函数。这是我使用的代码示例。
function doGet() {
var output = HtmlService.createTemplateFromFile("index");
output.content = "New string being passed";
return output.evaluate();
}
function doUpload(data){
logger.log(data);
Logger.log("I was called!")
}
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><?= content ?></title>
</head>
<body>
<h1><?= content ?></h1>
<div id="output"></div>
<form>
<input type="type" name="first" id="first" value="Laurence">
<input type="button" id="subButton" value="submit">
</form>
<script>
var output = document.getElementById("output");
var first = document.getElementById("first");
document.getElementById("subButton").addEventListener("click", function(e){
e.preventDefault();
output.innerHTML = first.value;
var myData ={"first":first.value};
console.log("hello");
google.script.run.doUpload(myData);
})
</script>
</body>
</html>
如您所见,我正在尝试 运行 执行上传(数据),但不会 运行。我已经把我所有的帐户都烧掉了,因为我认为这可能是问题所在,但事实并非如此。请帮忙,谢谢!
它对我有用:
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><?= content ?></title>
</head>
<body>
<h1><?= content ?></h1>
<div id="output"></div>
<form>
<input type="type" name="first" id="first" value="Laurence">
<input type="button" id="subButton" value="submit">
</form>
<script>
window.onload=function() {
var output = document.getElementById("output");
var first = document.getElementById("first");
document.getElementById("subButton").addEventListener("click", function(e){
e.preventDefault();
output.innerHTML = first.value;
var myData ={"first":first.value};
console.log("hello");
google.script.run.doUpload(myData);
});
}
</script>
</body>
</html>
检查你的view/executions