function startCampaign(index, campaign_id) {
var btn = $('#toggleStateBtn' + index);
btn.html('<i class="icofont-pause"></i>');
btn.removeClass('btn-success');
btn.addClass('btn-warning');
btn.attr('title', 'Pause this campaign');
btn.width('9px');
// Start campaign
$.ajax({
url: '/campaign/startCampaign/' + campaign_id,
type: 'POST',
success: function(data){
// Reflect the new state in status column
btn.html(data);
}
});
}
function pauseCampaign(index, campaign_id) {
var btn = $('#toggleStateBtn' + index);
btn.html('<i class="icofont-play"></i>');
btn.removeClass('btn-warning');
btn.addClass('btn-success');
btn.attr('title', 'Run this campaign');
btn.width('9px');
// Pause campaign
$.ajax({
url: '/campaign/pauseCampaign/' + campaign_id,
type: 'POST',
success: function(data){
// Reflect the new state in status column
btn.html(data);
}
});
}
For some reason this is causing strange behaviour. If you replace btn with $('#toggleStateBtn' + index) in all places then everything works fine.
My guess is, if for instance you first call startCampaign() and then called pauseCampaign() the old btn reference gets changed to the new one. But I'm not sure.
Ideas?