3
我正在开发Swift 4和Vapor 2.0的Web应用程序。我有一个POST
请求,这将创建一个新用户的方法:在Vapor中为html添加脚本动作
builder.post("user", "createUser") { (request) -> ResponseRepresentable in
但我不知道如何在.leaf
文件中添加了动作按钮调出createUser
方法。很容易在.html
文件中添加JavaScript操作,如<script src="js/index.js"></script>
。但随着蒸气,我没有看到Vapor 2.0 docs
更新有关的任何提及:
与@Caleb Kleveter的帮助下,现在它的工作。我更新了html
页面(只是为了测试,所以这不是一个好的页面):它会帮助新手面临同样的问题,使用vapor
。
这里是我的HTML内容:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Responsive Login Form</title>
<link rel='stylesheet prefetch' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css'>
<link rel="stylesheet" href="styles/app.css">
</head>
<body>
<link href='https://fonts.googleapis.com/css?family=Ubuntu:500' rel='stylesheet' type='text/css'>
<h3>
<form action="/user/createUser" method="POST" class="login-form">
<label for="username">Username:</label>
<input type="text" placeholder="Username" name="username"/>
<label for="password">Password:</label>
<input type="password" placeholder="Password" name="password"/>
<input type="submit" value="Login" class="login-button"/>
<form>
</h3>
<a class="sign-up">Sign Up!</a>
<br>
<h6 class="no-access">Can't access your account?</h6>
</div>
</div>
<!-- <div class="error-page">
<div class="try-again">Error: Try again?</div>
</div> -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>