So I've been having this isue for several days now. I'm trying to pass data into my serverside script, but when I do I get this error message. Error Message
I've tried watching several videos on youtube and they all say the same thing, that you have to use google.script.run. The problem comes with the function that is called after the run. Here is a sample of the code im using.
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>
As you can see im trying to run doUpload(data) but it wont run. I already singed out of all my accounts as I though that could be the issue but it wasn't. Please help, thanks!
It works for me this way:
<!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>
Check your view/executions