[英]unable to reference to .gs file within the google script created HTML
I am developing a web application using google script. 我正在使用Google脚本开发Web应用程序。 I created a simple login page within the google script. 我在google脚本中创建了一个简单的登录页面。 However, I tried to reference the .js(.gs) to the button to sent out the login info but it keep showing 400 error. 但是,我尝试将.js(.gs)引用到该按钮以发送登录信息,但它始终显示400错误。 I know I probably do it the wrong way. 我知道我可能做错了方式。 I just don't know how to do it. 我只是不知道该怎么做。
please help 请帮忙
<script src="/login_click.gs"></script>///reference to the gs file
.....
<button type="submit" onclick="login()">Login</button>///the login button
Client-to-server comms in GAS GAS中的客户端到服务器通讯
That's because .gs files are executed on the server and not on the client side. 这是因为.gs文件是在服务器而不是客户端上执行的。 Apps script has its own implementation of asynchronous server calls via the google.script.run
client API. Apps脚本通过google.script.run
客户端API具有自己的异步服务器调用实现。
Using google.script.run
is quite simple, you just call server-side functions by prepending their name like this google.script.run.yourServerFunction(yourParameters)
and, if your server-side function has return
statement, you can operate on the returned value via a callback client-side function passed to withSuccessHandler()
method (if you want to pass anything client-side to callback function after server-side function finishes executing, you can do so via withUserObject(dataToPass)
method call - just remember that the first argument of the success handler fucntion is always the value returned from server-side). 使用google.script.run
非常简单,您只需在服务器端函数前面google.script.run.yourServerFunction(yourParameters)
这样的名称即可调用它们,如果服务器端函数具有return
语句,则可以在通过传递给withSuccessHandler()
方法的回调客户端函数返回的值(如果要在服务器端函数完成执行后将任何客户端传递给回调函数,则可以通过withUserObject(dataToPass)
方法调用来实现-只要记住成功处理程序功能的第一个参数始终是服务器端返回的值)。
Modified html 修改的html
In your case, a simple modification will do the trick (assuming you are calling a server-side login()
function: 在您的情况下,简单的修改就可以解决问题(假设您正在调用服务器端login()
函数:
<script type="text/javascript">
function success(fromServer,fromClient) {
//doSomething on success;
}
function failure(error) {
//doSomething on failure;
}
function login() {
var myObject = ''; //add something to callback on success;
google.script.run
.withSuccessHandler(success)
.withFailureHandler(failure)
.withUserObject(myObject)
.login();
}
</script>
Useful links 有用的链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.