python - flask+ajax post 400错误
滿天的星座
滿天的星座 2017-05-18 10:46:36
[Python讨论组]

表单代码

mode_edit

ajax代码:

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 -
滿天的星座
滿天的星座

全部回复(1)
黄舟
cemail = request.form['email']

改为

cemail = request.form['cemail']

另外,你的form里有默认post 提交。如果想要自己处理的话,就不要在form里外加action 了。

$('.btn').click(function(event){
  event.preventDefault();
});
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号