javascript - 在 Flask 和 Javascript 中禁用和启用按钮
问题描述
可以在 Flask 中禁用和启用按钮吗?我有POST
请求Ajax
并将数据从 JavaScript 发送到 Flask,并从这个数据中创建response
一个带有弹出窗口的标记,并且有两个按钮one
和two
. 当用户单击时,one
他被添加到数据库中。在 Flask 中,我检查用户是否在数据库中,当他在数据库中时,此按钮对他禁用。这两个按钮也是提交表单的,我不知道我是否可以这样做。
代码烧瓶:
@app.route('/mapaa',methods=['GET','POST'])
def mapa():
if request.method == "POST":
if 'join-form' in request.form:
//check if is in the database
elif 'remove-form' in request.form:
//check if he is signed to the event
else:
name_ev = request.form.get('nameevent')
all_data = Event.query.filter_by(name=name_ev).all()
for row in all_data:
date_st_string = str(row.date_start)
date_end_string = str(row.date_end)
dictionary = {'id':row.id,'date_st':date_st_string,'date_end':date_end_string,'type':row.type,'name':row.name,'len_route':row.len_route,'route':row.route}
return jsonify(slownik)
// data to create marker
JavaScript 代码:
$("#search-button_event").one('click', function(e) { // make ajax request on btn click
e.preventDefault();
$.ajax({
type: "POST",
url: "/mapaa", // url to the function
data: {
nameevent: $("#name_of_event").val(), // value of the form
},
success: function(response) {
id = (response['id']);
data_end = (response['date_end']);
data_st = (response['date_st']);
len_route = (response['len_route']);
name = (response['name']);
let marker_event = L.marker(array[0]).bindPopup()
marker_event._popup.setContent(
'<form method="POST" action="/mapaa"' +
'<p>Name: ' + nazwa + '</p>' +
'<input name="nameOfEvent" type="hidden" value="' + nazwa + '" id="nameOF">' +
'<input id="ev_n" name="idOfEvent" type="hidden" value="' + id + '" id="idOF">' +
'<p>Date start: ' + data_st + '</p>' +
'<p>Date end: ' + data_end + '</p>' +
'<p>Typ: ' + typ + '</p>' +
'<p>Len route: ' + len_drogi + '</p>' +
'<button type="submit" id="one" name="join-form" class="btn btn-warning btn-block">Join to event</button>' +
'<br>' +
'<br>' +
'<button type="submit" id="two" name="remove-form" class="btn btn-danger btn-block">Sign out from the event</button>' +
'</form>')
marker_event.addTo(mymap)
polyline_event = L.polyline(array, {
color: 'red'
})
marker_event.on('click', function() {
polyline_event.addTo(mymap)
})
marker_event.getPopup().on('remove', function() {
polyline_event.remove()
})
mymap.setView(array[0], 14)
document.getElementById("name_of_event").value = "";
},
});
});
如果用户在数据库中,我想这样做,他将有禁用按钮加入。
解决方案
推荐阅读
- machine-learning - 使用随机森林作为带有 adaboost 的基础分类器
- flutter - Flutter GridView builder,每行具有动态高度和统一子级
- php - 导入类的 SmartGit 冲突错误
- countdowntimer - 通过代码在 Lightspeed 中添加倒数计时器
- firebase-storage - 如何在 Firebase 存储上按时间限制文件上传
- c++ - 向上或向下看时剔除截头锥体变窄
- python - 有限替换的python随机选择
- java - 自定义 jpackager(wix 工具集)
- c# - 构建解决方案时需要存在 .csproj nuget 包
- flutter - 当用户切换到新帐户时,如何停止对以前帐户的所有正在进行的呼叫?