表单代码
Username
URL
mode_edit
评论
取消
确认保存
ajax代码:
$(function(){
$('.btn').click(function(){
var $cname = $('input[name="cname"]').val();
var $cemail = $('input[name="cemail"]').val();
var $curl = $('input[name="curl"]').val();
var $text = $('textarea[name="comment"]').val();
var $res = $('#res');
$.ajax({
url:'/tpush/pl',
data: $('form').serialize(),
type: 'POST',
dataType:'json'
}).done(function (data) {
if (!data.r){
$res.html(data.rs);
}else{
$res.html(data.error);
}
});
});
});
python代码
@web.route('/tpush/pl',methods=['POST'])
def web_tpush():
cname = request.form['cname']
cemail = request.form['email']
curl = request.form['curl']
#ctext = request.form['ctext']
print(cname,cemail,curl)
error = None
if len(cname) < 2:
error = '666'
if len(cemail) < 5:
error = '777'
if error is not None:
return jsonify({'r':1,'error':error})
return jsonify({'r':0,'rs':ok})
我点击提交后跳转到/tpush/pl
提示:
4000 Bad Request
The browser (or proxy) sent a request that this server could not understand.
127.0.0.1 - - [13/May/2017 19:57:42] "POST /tpush/pl HTTP/1.1" 400 -
127.0.0.1 - - [13/May/2017 19:57:42] "POST /tpush/pl HTTP/1.1" 400 -