我已經寫過,使用Jquery的AJAX腳本。當我通過腳本進行調試時,我注意到它沒有經過「成功」和「錯誤」但它存在。如何在Python中使用Ajax燒瓶
這裏是jQuery代碼
$(document).ready(function(){
$('#report-submit').click(function() {
alert('inside click');
$.ajax({
url: '/admin/file/start/rerun_reports/',
//data: $i('form').serialize(),
type: 'POST',
success: function(response) {
//alert(response);
console.log("it works..................");
console.log(response);
$("#log-results").html(response);
},
error: function(error) {
console.log(error);
}
});
});
});
然而,當我提交按鈕,我得到的數據,瀏覽器,而阿賈克斯。
下面是HTML代碼
<form method="POST" action="/admin/file/start/rerun_reports/">
<input name="_csrf_token" type=hidden value="{{ csrf_token() }}">
<input class="btn btn-danger btn-lg" id="report-submit"
type="submit" value="submit">
</form>
在這裏,我將數據發送到瀏覽器
return render_template('tools.html', data = json.dumps(start.logdata))
當打印狀態代碼。我得到了403 error
。
我猜你使用Flask- WTF for CSRF? – nathancahill 2015-04-02 20:43:53
我已將CSRF令牌添加到html表單。還要別的嗎? – newday 2015-04-02 21:52:54
如果你使用Flask-WTF,你可以寫'{{form.csft_token}}' – nathancahill 2015-04-02 22:21:34