codler/jQuery-Ajax-Upload

Click function should be bound using on()

Closed this issue · 5 comments

On line 297, the click function should be bound using on() - I've added this hack to my file, although it's probably not the best solution.

var id = $(this).attr('id');
$(document).off().on('click', '#' + id, function () {
    $.ajaxUploadPrompt( origSettings );
});

Hm, Why do we need it? What is the difference?

That's the new way of event binding. And using on is the encouraged way of coding jQuery as click might be depreciated.

I'm asking for this patch because the event isn't binding properly in my current code. With the non-deprecated jQuery calls, it works correctly.

From live docs page:

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.

From bind cods page:

As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document.

Using off() is not a good solution. It disables all events.

Would this work instead?

$(this).on('click.ajaxupload', function () {
  $.ajaxUploadPrompt( origSettings );
});