weixin_33699914 2018-11-29 20:35 采纳率: 0%
浏览 558

为什么提交表单时收到了404错误?

我在提交表单时收到了404错误提示。我试图通过该表格上传并提交.png,按理来说服务器(Python,Flask)应该能够使用它才对......有人知道我的问题出在哪里吗?

AJAX:

<script>
    document.getElementById("exampleFormControlFile1").onchange = function() {
    console.log("Came here");
    $.ajax({
        url:'/uploadPNG/',
        type:'post',
        data:$('#exampleFormControlFile1').serialize(),
        success:function(){
            console.log("Came here");

            }
});
};
</script>

HTML:

<form method="POST" id="form">
    <div class="form-group">
    <label for="exampleFormControlFile1">Upload your .png template</label>
    <input type="file" class="form-control-file" id="exampleFormControlFile1">
    </div>
</form>

SERVER:

@app.route('/uploadPNG/', methods=['POST'])
def upload():
    if request.method == 'POST':
        print("Got png")
    return "gotcha"

提前感谢你的解答!

  • 写回答

1条回答 默认 最新

  • weixin_33688840 2018-12-01 10:32
    关注

    I just figured out the issue. Gonna answer my own post here so that others may have it easier. A magic wizard once told me to always check the documentation. http://flask.pocoo.org/docs/1.0/patterns/fileuploads/ Then I had to adjust the AJAX call like here: 'append' called on an object that does not implement interface FormData And then i had to add the name "file" to the input tag.

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用