Binding jquery-multifile to a dynamically loaded form

﹥>﹥吖頭↗ 提交于 2020-01-15 19:13:20

问题


I am using the jquery multifile plugin found here:

http://www.fyneworks.com/jquery/multiple-file-upload/

I've used it in the past and had no problems, but now I am trying to use it in a dynamically loaded form and it's causing a strange issue.

I am binding the function correctly when loading the form as per this article, so please understand this is a DIFFERENT, albeit related, problem to the one posted here:

Cannot bind input event to jQuery multifile from dynamically loaded form

$('#reportWindow').on('click', '#continueReport', function () {
    var data = $('.reportForm').serializeObject();
    $('<div/>').load('/Forms/report.aspx', data, function () {
        doReportForm(this);
    });
});

An ASPX file is being loaded into a div using jquery load as per the above, the doReportForm function is to call in various binding methods to that dynamically generated HTML as per:

function doReportForm(ele) { 
    $(ele).makeModal('', 800);
    FB.XFBML.parse();
    checkLogin();
    clearNetIds($('#reportForm2'));

    $("#datePicker").datepicker({
        changeMonth: true,
        changeYear: true
    });

    $('[class*="toolTip"]').setupTip();
    $(".multi").MultiFile(); // input[type=file]

    $('#right').on('click', '#savePost', function () {
        var data = $('.reportForm2').serializeObject();
    });
};

The first line there, $(ele).makeModal('', 800); is simply a jQuery extension I made to create modal windows, so it as it THIS point where the element is added to the DOM, then a few lines down I bind the MultiFile plugin thus $(".multi").MultiFile();

The first time this is done, it works fine. But, when a user closes the modal window and then tries to load the form again I get an error.

Uncaught TypeError: Cannot call method 'apply' of undefined

(closing the modal window removes it completely from the DOM with jQuery.remove(), so any future windows are written completely from fresh).

After a bit of fiddling, it appears that this is due to jQuery not being able to access the MultiFile script... I think

The MultiFile script is loaded in the head of the parent document, so should be available at all times.

来源:https://stackoverflow.com/questions/14155793/binding-jquery-multifile-to-a-dynamically-loaded-form

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