2015-10-21 49 views
0

我有阿賈克斯jQuery的文件上傳,它工作正常在Chrome,火狐但不工作的IE瀏覽器和微軟的邊緣。它並沒有給我任何迴應,我嘗試了所有可能的解決方案,並且仍然沒有工作..阿賈克斯jQuery的文件上傳在IE11和微軟邊緣不工作

這裏是我的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> 

哪有修復它!?

+0

你看到任何**控制檯錯誤**?在IE中? –

回答

0

我覺得這個問題是你是你的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); 
     } 
    }); 
}); 
+0

仍然無法使用! – iOsam4h

+0

然後有什麼錯誤? –

+0

它只是提交,發送POST請求沒有任何迴應upload.php的! – iOsam4h