Reputation: 532
as the title suggests, I have the following function:
$('.breadCrumb').on('click',function(){
var bc = $(this).prop('id');
var id = bc.split('_');
$('#'+bc).removeClass("breadCrumb");
//$('.'+bc).show();//show spinner on specific id
$.ajax({
url:'/ajax/breadcrumb/',
data:{bc:id[1]}
}).success(function(breadcrumb){
$('#'+bc).html(breadcrumb);
//$('.spinner').hide();
});
});
The problem is, I am able to click again (for whatever reason) and I want to prevent someone from just clicking away and sending a query to the db every time, and
$('#'+bc).removeClass("breadCrumb");
is not working. Can I get any advice? Thanks!
Upvotes: 2
Views: 330
Reputation: 4751
Change $('.breadCrumb').on('click',function(){
to $('body').on('.breadCrumb', 'click',function(){
Upvotes: 0
Reputation: 247
$('.breadCrumb').on('click',function(){
$(this).off('click');
var bc = $(this).prop('id');
var id = bc.split('_');
$('#'+bc).removeClass("breadCrumb");
//$('.'+bc).show();//show spinner on specific id
$.ajax({
url:'/ajax/breadcrumb/',
data:{bc:id[1]}
}).success(function(breadcrumb){
$('#'+bc).html(breadcrumb);
//$('.spinner').hide();
});
});
Upvotes: 2