这是AJAX调用
$(function(){
$("[type=submit]").click(
function(){
event.preventDefault()
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + "/query",
contentType: "application/json; charset=utf-8",
data:$('.form-horizontal').serialize() ,
success: function() {
console.log('worked');
},
error:function(){
console.log('didn\'t work')
}
})
})
})
以下是路线:
@app.route('/query',methods=['POST'])
def query():
return request.form['startdate']
我现在正在测试它,但我无法从查询路径返回任何内容。不是request.form
(或上面的startdate中的任何特定值),而不是request.data
,没有。 Request.data
为空,request.form
为空的immutablemultidict。
相关HTML:
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="start_date">Start Date:</label>
<div class="col-sm-10">
<input type="date" class="form-control" id="datetimepicker1",name='startdate'>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="end_date">End Date:</label>
<div class="col-sm-10">
<input type="date" class="form-control" id="datetimepicker2",name='enddate'>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>