Download jQuery file after page load

I have a page that loads an HTML form through a $ .ajax request.

The form has the ability to upload files. I tried several Ajax download plugins, and all of them require me to instantiate some object like ajaxUpload (), which internally creates a click listener. However, these listeners do not start because the dynamically loaded form is not accessible by the DOM.

To get around such things in the past, I used live () to listen. But I can not declare these ajaxUpload instances as a live event. So, how can I make this boot button function?

+4
source share
7 answers

I solved this using another uploader plugin https://github.com/valums/file-uploader

which allows me to call a function to create a loader from a DOM element at any desired time. Therefore, I can only call a function when I need a loader. Thus, I do not need to rely on live events.

0
source

I seem to recall somewhere that the livequery plugin can handle this type of thing. In search of truth, I came across this:

JQuery binding problem for copied elements

+1
source

AJAX cannot load the file. jQuery form plugins using a hidden iframe technique to upload a file. To perform an actual AJAX boot, you can use the Flash-based bootloader. I recommended you try uploadify .

+1
source

What do you mean that the form is not available in the DOM after receiving it using ajax? Why should it not be?

$.get(url_that_has_form, null, function(resp) { $('#some_container').html(resp); // Now the form is part of the document. // Run your ajax upload stuff here. new AjaxUpload('#id_of_form_you_just_added', options); }, 'html'); 
+1
source

Could you add a dynamically loaded form to the document? (then create an instance of the ajaxUpload object `` after '' the form is added to the document)

0
source

Here is the best I've been able to do so far:

 $('#uploadButton').live('click', function(){ new AjaxUpload('uploadButton', { action: 'upload-handler.php', onComplete: function(file, response){ alert(response); }); }); 

live () works, but it only creates an object after a click. So I need to click it again for the boot trigger to work.

So, I was trying to somehow remove the extra click. I was hoping the following would work at the end of the function, but it is not:

 $(this).trigger("click"); 
0
source

@lawrence thanks, I faced the same problem, after loading html as part of the form, congruent loading elements, I need to double-click. Although I tried many methods to override the click descriptor after loading html, but failed.

At the end of the page, I read this $ (This) .trigger ("click"); and I change it to satisfy me and place at the end of the ajax call, and it works. . JQuery ("#loads") trigger ("click"); Hooray ... Thanks to every body.

0
source

Source: https://habr.com/ru/post/1299993/


All Articles