jQuery live click fires more than once
I have this code for ajax a page on search click:
$.ajax({
url: "ClientsList.asp",
type: "POST",
data: "name=" + Name + "&org=" + Org + "&job=" + Job + "&type=" + Type,
success: function(msg){
$("#SRP").html(msg);
$("#Loading").fadeOut("noraml",function(){
$("#SRP").fadeIn();
});
}
});
then in the content loaded I have checkboxes that I need to catch, so I do that with this code
$(".SearchResultSelectBox").live("click", function(event) {
$(this).is(":checked") ? DoCheckSelect($(this).attr("rel")) : unDoCheckSelect($(this).attr("rel"));
});
The first time I search and get the resulted page from the ajax the checkbox work great. the second time I use the search, every live click I have is doubled. the third time I use the ajax, every live click is tripled and so on...
I tried "return false" but then it work but the checkbox doesn't get 开发者_JS百科clicked
What can be done?
NEVER MIND! I had a mistake, I had the second set of function inside of the first one so every time I made the search function I made the inside function for live click again
may be try to use
unbind('click');
and bind it again for each ajax request
Try
event.stopPropagation();
$(".SearchResultSelectBox").live("click", function(event) {
$(this).is(":checked") ? DoCheckSelect($(this).attr("rel")) : unDoCheckSelect($(this).attr("rel"));
event.stopPropagation();
});
精彩评论