dongxian1921 2012-02-15 13:18
浏览 37
已采纳

多个uploadify图片上传问题

I am using multiple uploadify instances on single page. But the problem is that when I submit the form,form gets submitted before the upload of all the files.

I tried event.preventDefault(); to prevent the form submission before the image upload. but I am not getting the solution. Please suggest me some way by which I can prevent the form submission until all the uploadify files gets uploaded.

Here is my function

$("#add_facility_form .form-submit").click(function(event){

        event.preventDefault();
      $('#gallary').uploadifyUpload();
      $('#brochures').uploadifyUpload();
      $('#award_logo').uploadifyUpload();
      $('#acc_logo').uploadifyUpload();
      $('#file_upload').uploadifyUpload();

       $("#add_facility_form").submit();
  });
  • 写回答

3条回答 默认 最新

  • douhao8456 2012-02-15 13:30
    关注

    I would suggest using classes for your file uploads - will reduce your jQuery code .. for example ...

    <input type="file" id="file1" name="file1" class="uploadifyfile" />
    <input type="file" id="file2" name="file2" class="uploadifyfile" />
    <input type="file" id="file3" name="file3" class="uploadifyfile" />
    

    Then your jQuery becomes :

    $("#add_facility_form").submit( function(event){
        $('.uploadifyfile').uploadifyUpload(); // uses class instead of multiple IDs
        if (numFilesUploaded < $(".uploadifyQueueItem").length) { return false; }
    });
    

    Then when you initialise the uploadify elements add an onComplete method to keep a track of the completed uploads :

    $(".uploadifyfile").each(function () {
        $(this).uploadify({
           'onComplete': function (event, queueId, fileObj, response, data) {
             incrementUploadedCount();
           }
        });
    });
    

    Then create a variable for keeping a track of the completed uploads then in the incrementUploadedCount function check that all have been complete, if they have submit the form

    // keep track of uploaded count 
    var numFilesUploaded = 0;
    
    function incrementUploadedCount() {
        numFilesUploaded++; // increment complete count
        // check if complete count matches number of uploadify elements
        if (numFilesUploaded == $(".uploadifyQueueItem").length) {
             // submit your form
             $("#add_facility_form").submit();
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?