我已经写过,使用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