Valums qq.FileUploader doesn't work when it's initialized after loading button by ajax

社会主义新天地 提交于 2020-01-25 08:36:25

问题


I use Valums qq.FileUploader(ex-AjaxUpload) plugin for uploading in my Asp.net mvc 3 application...

I have some button in my page add-newimage, and by clicking in it I get modal window, and I load data into that window by loading Partial View.

And in that partial view I have button upload-image , in which I want to initilaize my qq.FileUploader, but it doesn't work anywhere...

Here is code

      $("#add-newimage").click(function () {
            $("#add-image").load('/Design/AddImage/', function () {
                $("#add-image").dialog('open');

                     var uploader= new qq.FileUploader({
                    element: document.getElementById("upload-image"),
                    action: '/Design/UploadImage',
                    allowedExtensions: ['jpg'],
                    onComplete: function (id, fileName, responseJSON) {
                        $("#hidden-path input").html("/Img/Temp/@User.Identity.Name/" + file);
                        alert($("#hidden-path input").html());
                    }

                     }); 
            }); 
        });

How can I make it work?


回答1:


I would try to put the uploader code in the open event of your dialog.

$("#add-image").dialog({
  open : function(event, ui) {
      var uploader= new qq.FileUploader({
        element: document.getElementById("upload-image"),
        action: '/Design/UploadImage',
        allowedExtensions: ['jpg'],
        onComplete: function (id, fileName, responseJSON) {
          $("#hidden-path input").html("/Img/Temp/@User.Identity.Name/" + file);
            alert($("#hidden-path input").html());
          }
  }
});

..

$("#add-newimage").click(function () {
  $("#add-image").load('/Design/AddImage/', function () {
    $("#add-image").dialog('open');
  });
});


来源:https://stackoverflow.com/questions/7592787/valums-qq-fileuploader-doesnt-work-when-its-initialized-after-loading-button-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!