weird problem with load () or live () !!

Posted by silversky on Stack Overflow See other posts from Stack Overflow or by silversky
Published on 2010-03-30T02:27:49Z Indexed on 2010/03/30 2:33 UTC
Read the original article Hit count: 360

Filed under:
|
|
|
|

I load a page with load () and then I create dinamically a

tag. Then I use live() to bind a click event and fires a function. At the end a call unload ().

The problem is that when I load the same page again ( without refresh ) when on click the function will be fired twice. If I exit again (again with unload ()) and load the page again on click will fire 3 times and so on .... A sample of my code is:

$('#tab').click(function() {
 $('#formWrap').load('newPage.php');
});
$('div').after('<p class="ctr" ></p>');
$('p.ctr').live('click', function(e) {
   if($(e.target).is('[k=lf]')) { console.log ('one'); delete ($this); }
   else if ....
});
function delete () {
  $.post( 'update.php',  data);
}

I have other $.post inside on this page and also on the above live fnc and all work well. The above one also works but like I said on the second load will fire twice and the 3 times and so on ... The weird part for me is that if replece the console with console.log ('two'); save the page and load the page without refresh it will fire on a different rows - one two -

if I unload the page replace the console with console.log ('three'); and load again will fire one two and three. I try to use:

$.ajax({ url: 'updateDB.php', data: data, type: 'POST', cache:false });

$.ajaxSetup ({ cache: false });

header("Cache-Control: no-cache");

none of this it's working. And I have this problem only on this fnc. What do you think, it could be the reason, it remembers it remembers the previous action and it fires again?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about live