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>