模态窗口中的ajax文件上传

时间:2013-02-26 20:26:05

标签: javascript jquery ajax jquery-ui file-upload

因为用户上传的某些文件很大,我希望在模态窗口内进行上传,以便在上传过程中自由导航。我无法将模态窗口集成到jquery中。有人能帮忙吗。感谢

function upload() {
  var fileInput = $('#file')[0];
  var data = new FormData();

for(var i = 0; i < fileInput.files.length; ++i){
    data.append('file[]',fileInput.files[i]);
}
$.ajax({
    type:'POST',
    method:'POST',/* for newest version of jQuery */
    url:'upload.php',
    headers:{'Cache-Control':'no-cache'},
    data:data,
    contentType:false,
    processData:false,
    success: function(response){
        var return_data = response;
        alert(return_data);
        if(return_data !== 'success') {
             failed();
        }
        else if(return_data == 'success') {
            success();
        }         
      }
    });
 }   
   <boby>
     <form id="form" method = "POST" enctype="multipart/form-data">
        <input type = "file" id = "file" multiple />
     </form>
  </body>

0 个答案:

没有答案