doublestar2014
2018-05-24 16:10
浏览 554

ajax上传文件formdata看起来是空的

Does not send to php anything. And When I tried to show results on form data it looks empty.

My Form:

    <form id="uploadform1236-1" method="POST" enctype="multipart/form-data" onsubmit="uploadprove('uploadform1236-1', event, 'post.php?action=uploadprove');">
<input name="picture" id="file-upload1236-1" class="" type="file">
<input name="testx" id="xxx1" class="" value="test1236" type="text">
<button id="uploadbutton1236-1" class="btn btn-primary btn-sm" type="submit">ttt</button>

</form>

Javascript:

function uploadprove(id, e, url) {
        e.preventDefault();
        var uploadform = $('#' + id)[0];
        var formData = new FormData(document.getElementById(id)); //also tried to put uploadform variable here
        alert(uploadform.toSource()); // results are ({0:{},1:{},2:{}}) It sees that 3 elements in form
        alert(formData.toSource()); // results are ({})
        $.ajax({
            url: url,
            type: "POST",
            data: formData,
            ContentType: false,
            ProcessData: false,
            success: function (data) {


                alert(data);


            }
        })
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzou9047 2018-05-24 17:25
    已采纳

    Your fields ContentType and ProcessData are wrong they are contentType and processData

    $.ajax({
        url: url,
        type: "POST",
        data: formData,
        contentType: false,
        processData: false,
        success: function (data) {
            alert(data);
        }
    })
    
    点赞 打赏 评论

相关推荐 更多相似问题