Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#12437 closed bug (notabug)

.on() not working on version 1.8.1 after ajax call

Reported by: jgleiser Owned by: jgleiser
Priority: blocker Milestone: 1.8.2
Component: event Version: 1.8.1
Keywords: Cc:
Blocked by: Blocking:

Description

I have the following code before the $.ajax function

var resultados = $("#resultados-filtro");

resultados.find(".list-pager").on("click",'a',function(e){e.preventDefault();});

resultados.find('.ver-detalles').on('click', function(e){e.preventDefault();});

resultados.find('.comparar').on('click', function(e){e.preventDefault();});

And I have the following function inside an $.ajax call after success

success: function(data, textStatus, jqXHR){

resultados.find(".list-pager").off("click",'a');

resultados.find('.ver-detalles').off('click');

resultados.find('.comparar').off('click');

resultados.html($(data).find("#tabla-resultados"));

resultados.find(".list-pager").on("click",'a',function(e){e.preventDefault();});

resultados.find('.ver-detalles').on('click', function(e){e.preventDefault();});

resultados.find('.comparar').on('click', function(e){e.preventDefault();});

}

The problem is that after the ajax call, the .on() events doesn´t register. It works with jquery 1.8.0 and olders but in 1.8.1 I get the href from elements fired instead the preventDefault().

Change History (7)

comment:1 Changed 7 years ago by dmethvin

Owner: set to jgleiser
Status: newpending

Please provide a test case at jsfiddle.net or jsbin.com.

comment:2 Changed 7 years ago by jkane001@…

I don't have code I can easily put on jsfiddle, but I can second this - it's not just "on()", either - no click events seem to get handled (by jQuery) after an ajax call.

comment:3 Changed 7 years ago by dmethvin

Great, we'll start looking at that right a...whoops, still no test case. If you can't reduce it, please head over to http://forum.jquery.com or StackOverflow and see if people there can help you figure out whether this is a bug or not.

comment:4 Changed 7 years ago by dmethvin

Component: unfiledevent
Milestone: None1.8.2
Priority: undecidedblocker
Status: pendingopen

I'll mark this as blocking 1.8.2 pending investigation but we MUST have more information to help track this down.

comment:5 Changed 7 years ago by dmethvin

Resolution: notabug
Status: openclosed

We have not had any additional reports and have not received any test cases, so I'm closing this ticket.

comment:6 Changed 7 years ago by loon88@…

i do have the same issue when using 1.8.1, the e.preventDefault() just doesn't work in dynamic generated contents. i am using .on(). but it works in 1.8.2.

comment:7 Changed 7 years ago by mikesherov

Please provide a test case that demonstrates this issue if you are still experiencing one. Thanks!

Note: See TracTickets for help on using tickets.