我正在使用 python Flask,但我在想的是 Javascript。我尝试按照本网站上的教程进行操作。
这家伙有这样的功能(第 4 步):
$(function() {
$('#btnSignUp').click(function() {
$.ajax({
url: '/signUp',
data: $('form').serialize(),
type: 'POST',
success: function(response) {
console.log(response);
},
error: function(error) {
console.log(error);
}
});
});
});
让我解释一下到目前为止的设置。
在 html 的正文中,我有
<button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="button"
onclick="palValidateSignUp()">Sign up</button>
在我的页面 HTML 中,我有
<script src="../static/jquery.js">
function palValidateSignUp()
{
FUNCTION FROM TUTORIAL IN HERE
}
</script>
我想要的是
我需要创建新文件吗?我把代码放在哪里,我叫它什么?我知道这对很多人来说是最简单的,只是不适合我!
我只是重新安排您的代码并将其作为答案放在这里,因为我觉得您非常需要一个 html 样板代码;
我不能保证它是否会起作用,我只是为您指明正确的道路。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title of Your Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="button" onclick="palValidateSignUp()">Sign up</button>
</body>
<script type="text/javascript">
function palValidateSignUp() {
$(function() {
$('#btnSignUp').click(function() {
$.ajax({
url: '/signUp',
data: $('form').serialize(),
type: 'POST',
success: function(response) {
console.log(response);
},
error: function(error) {
console.log(error);
}
});
});
});
}
</script>
</html>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句