Ajax POST 请求 Flask 应用程序
Ajax POST Request to Flask Application
我正在尝试使用输入类型按钮从 ajax 创建一个 POST 请求。但是请求没有发送
需要发送两个单独的请求,如下所示
html
<input type="button" class="far fa-check-circle" name="hvalid" id="hvalid">
<input type="button" class="fas fa-times-circle" name="hinvalid" id="hinvalid">
ajax
$(function(){
$('input').click(function(){
var hvalid = $('#hvalid').val();
var hinvalid = $('#hinvalid').val();
$.ajax({
url: '/pending_val',
data : {'hvalid':hvalid,
'hinvalid':hinvalid},
type: 'POST',
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
});
});
烧瓶路线
@data_sources_api.route('/pending_val', methods=["GET", "POST"])
def pending_val():
if request.method=='POST':
print(request.form)
hvalid
和hinvalid
请求如何分开发送
html
<input type="button" class="far fa-check-circle" name="hButton" id="hvalid">
<input type="button" class="fas fa-times-circle" name="hButton" id="hinvalid">
ajax
$(function(){
$('input[name="hButton"]').click(function(){
$.ajax({
url: '/pending_val',
data : {'hvalidity': this.id },
type: 'POST',
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
});
});
烧瓶
data_sources_api.route('/pending_val',methods=["GET", "POST"])
def pending_val():
if request.method=='POST':
print(request.form.get('hvalidity'))
return json.dumps({'success':True}), 200, {'ContentType':'application/json'}
我正在尝试使用输入类型按钮从 ajax 创建一个 POST 请求。但是请求没有发送
需要发送两个单独的请求,如下所示
html
<input type="button" class="far fa-check-circle" name="hvalid" id="hvalid">
<input type="button" class="fas fa-times-circle" name="hinvalid" id="hinvalid">
ajax
$(function(){
$('input').click(function(){
var hvalid = $('#hvalid').val();
var hinvalid = $('#hinvalid').val();
$.ajax({
url: '/pending_val',
data : {'hvalid':hvalid,
'hinvalid':hinvalid},
type: 'POST',
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
});
});
烧瓶路线
@data_sources_api.route('/pending_val', methods=["GET", "POST"])
def pending_val():
if request.method=='POST':
print(request.form)
hvalid
和hinvalid
请求如何分开发送
html
<input type="button" class="far fa-check-circle" name="hButton" id="hvalid">
<input type="button" class="fas fa-times-circle" name="hButton" id="hinvalid">
ajax
$(function(){
$('input[name="hButton"]').click(function(){
$.ajax({
url: '/pending_val',
data : {'hvalidity': this.id },
type: 'POST',
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
});
});
烧瓶
data_sources_api.route('/pending_val',methods=["GET", "POST"])
def pending_val():
if request.method=='POST':
print(request.form.get('hvalidity'))
return json.dumps({'success':True}), 200, {'ContentType':'application/json'}