【问题标题】:Ajax Jquery File Uploader not working in IE11 & Microsoft EdgeAjax Jquery 文件上传器在 IE11 和 Microsoft Edge 中不起作用
【发布时间】:2016-04-20 21:32:16
【问题描述】:

我有 ajax jquery 文件上传器,它在 Chrome、Firefox 中运行良好,但在 IE 和 Microsoft Edge 上无法运行。它没有给我任何回应,我尝试了所有可能的解决方案,但仍然无法正常工作..

这是我的 JS:

$('form').on('submit', function(event) {
    event.stopPropagation();
    event.preventDefault();


    $.ajax({
        url: 'upload.php',
        type: 'POST',
        data:  new FormData(this),
        cache: false,
        dataType: 'json',
        processData: false,
        contentType: false,
        success: function(data, textStatus, jqXHR)
        {
            console.log(data)


        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            console.log('ERRORS: ' + textStatus);
        }
    });

});

和我的表格:

<form method="post" enctype="multipart/form-data">
  <input name="file[]" type="file" required multiple />
  <input type="radio" name="something" value="1"> 1
  <input type="radio" name="something" value="2"> 2
</form>

怎么解决!?

【问题讨论】:

  • 您是否看到任何控制台错误?在 IE 中?

标签: javascript jquery ajax file-upload internet-explorer-11


【解决方案1】:

我觉得问题在于您将data 分配给ajax 的方式。当你在new FormData 中说this 时,它实际上是用ajax call 而不是form。所以最好把这个概念放在外面,然后再试一次。

$('form').on('submit', function(event) {
    //event.stopPropagation();//I don't think this is necessary
    event.preventDefault();
    var formdata=new FormData($('form').get(0)) //try with this here
    $.ajax({
        url: 'upload.php',
        type: 'POST',
        data:  formdata,
        cache: false,
        dataType: 'json',
        processData: false,
        contentType: false,
        success: function(data, textStatus, jqXHR)
        {
            console.log(data)
        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            console.log('ERRORS: ' + textStatus);
        }
    });
});

【讨论】:

  • 它只是提交并发送请求POST到upload.php,没有任何响应!
  • @iOsam4h 我认为你真的需要调查一下this post
猜你喜欢
  • 1970-01-01
  • 2019-12-13
  • 2017-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
相关资源
最近更新 更多