doublestar2014 2018-05-24 16:10
浏览 800
已采纳

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);
        }
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,