我想让一个 html 按钮将我重定向到烧瓶中的另一个端点



我正在制作一个刽子手应用程序,它将pingMerriam-Webster的api。我仍处于开发和学习瓶的初始阶段,但我想在一个显示按钮的端点中呈现一个 html 模板。这个按钮,onClick,应该将我重定向到另一个端点,有点像"选择你的模式"选项。

唯一的问题是我无法弄清楚我是否应该使用jquery,ajax,js或只是html,或者这些实际上是如何工作的。我以前只做过 GET 请求。

这是我的端点片段,然后是我在网上找到的一些 html:

@app.route('/main', methods=['GET', 'POST'])
def main_screen():
return render_template('main.html')

@app.route('/main/receive_data', methods=['POST', 'GET'])
def data_screen():
the_id = request.args.get('button_id')
return "<p>Got it!</p>"

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<tr><td>
<button id="socks.shirt.pants" type='button'> dummy text here</button>
<div id='response'></div>
</td></tr>
</body>
<script>
$(document).read(function() {
$("button").click(function(event){
var the_id = event.target.id;
$.ajax({
url: "/recieve_data",
type: "get",
data: {button_id: the_id},
success: function(response) {
$("#response").html(response);
},
error: function(xhr) {
//Do Something to handle error
}
});
});
});
</script>
</html>

我认为首先你想要:

正确:$(文档(。ready(function(( {

不是:$(文档(。read(function(( {

看看这是否有助于您的情况

最新更新