簡體   English   中英

Ajax Jquery File Uploader在IE11和Microsoft Edge中不起作用

[英]Ajax Jquery File Uploader not working in IE11 & Microsoft Edge

我有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>

怎么解決!!

我覺得問題出在您向ajax分配data的方式上。 當您在new FormDatathis句話時,它實際上是通過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);
        }
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM