2016-09-28 60 views
1

我試圖上傳我的多個文件時遇到問題。我有兩種方法通過ajax發送到一個頁面。一個是dropzone,另一個是我的XMLHttpRequest。每次我通過單擊按鈕發送時,它只會複製我的請求,只使用第一種方法,即dropzone並忽略我的XMLHttpRequest。所以我試圖找出將它綁定到formData的方式,使它只有1個文件一起請求。JQuery:如何使用dropzone.js將多個文件放入formData並通過ajax發送

我的形式

 <form style="border:3px dashed #D9EDF7;" action="UploadImage" 
       class="dropzone dz-clickable" 
       id="my-awesome-dropzone" enctype="multipart/form-data"> 
       <div class="dz-message">Drop files here or click to upload. 
         <br> <span class="note">(Selected files are not 
       automatically uploaded.)</span> 
        </div> 
      <div class="fallback"> 
       <input name="file" id="filez" type="file" multiple/> 
      </div> 

     </form> 

我的js

Dropzone.autoDiscover = false; 
var myDropzone = new Dropzone('#my-awesome-dropzone', { 
    url : '../ajax/ajax_add/ajax_addNEWContestant.php? 
    multipleImage=multiple_image&event_id='+event_id, 
    autoProcessQueue : false 
}); 

$(document).on('click','#addnewContestant', function(e){ 
    myDropzone.processQueue(); 

    var formdata = new FormData(); 
    formdata.append('file_addnew', file_addnew.files[0]); 
    //If there is a way, I just want to bind all the files from dropzone into formData 
    var data = new FormData(); 
    for(var b=0; b<imageContainer.length; b++){ 
     formdata.append('All_files_from_dropzone[], input_file.files[b]); 
    } 



    var param = "?event_id="+encodeURIComponent(event_id)+ 
      "&contestant_name="+encodeURIComponent(contestant_name)+ 
      "&contestant_lastName="+encodeURIComponent(contestant_lastName)+ 
      "&conAge="+encodeURIComponent(conAge)+ 
      "&hAddress="+encodeURIComponent(hAddress)+ 
      "&email_add="+encodeURIComponent(email_add)+ 
      "&conContactNum="+encodeURIComponent(conContactNum)+ 
      "&conDesc="+encodeURIComponent(conDesc)+ 
      "&conId_hidden="+encodeURIComponent(conId_hidden)+ 
      "&hidden_gender="+encodeURIComponent(hidden_gender)+ 
      "&random_gender="+encodeURIComponent(random_gender)+ 
      "&multipleImage="+encodeURIComponent(multipleImage); 


    beforeSend();    
    xhr = new XMLHttpRequest(); 
    var url = '../ajax/ajax_add/ajax_addNEWContestant.php'; 
    xhr.open('post', url+param, true); 

}); 

回答

1

懸浮窗會已經提交其他表單字段與文件一起,所以你不需要做任何工作XHR自己

相關問題