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 cpuid是如何转换的
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker
  • ¥15 Spring MVC项目,访问不到相应的控制器方法
  • ¥15 esp32在micropython环境下使用ssl/tls连接mqtt服务器出现以下报错Connected on 192.168.154.223发生意外错误: 5无法连接到 MQTT 代理,如何解决?
  • ¥15 关于#genesiscsheel#的问题,如何解决?
  • ¥15 Android aidl for hal
  • ¥15 STM32CubeIDE下载程序报错
  • ¥15 微信好友如何转变为会员系统?(相关搜索:小程序)
  • ¥15 c# 直接使用c++ 类库文件