I have this piece of code
$(document).ready(function() {
$(".spam").on("click", function(e){
//var pid=$(this).attr('id');
//var fav_btn=$(this).attr('id');
$path=$(location).attr('href');
$.ajax({
url:site_root +"/insert_spam.php",
type:"POST",
data:{ 'path':$path},
'success':function($result)
{
// alert($result);
if($result=="suc")
{
$(".spam").removeClass('spam').addClass('reported_spam');
}
else if($result=="err") { alert("Not able to report
to admin. Please contact admin");}
},
// 'error':function($e){ alert($e);}
});
return false;
});
});
========================================================
$(document).ready(function() {
$(".reported_spam").on("click", function(){
$path=$(location).attr('href');
$.ajax({
url:site_root +"/insert_spam.php",
type:"POST",
data:{ 'path':$path},
'success':function($htm)
{
//alert($htm);
if($htm=="suc2")
{
//$(".social span.reported_spam").removeClass('reported_spam').addClass('spam');
$('span.reported_spam').removeClass('reported_spam').addClass('spam');
// e.stopPropagation();
}
else if($htm=="err2") { alert("Not able to report to
admin. Please contact admin");}
}
});
return false;
});
});
========================== html ============================
<span class="glyphicon glyphicon-ban-circle spam
pull-right "></span>
STEP1. when I click on spam button it is working fine it updates
the database and adds the ".reported_spam" class and
removes ".spam" to the span tag and changes the color
STEP2. but immediately after this if I click again it does not
removes the ".reported_spam" class and
adds".spam" class even though database is updated
But if after STEP 1. if I refresh the browser and then click again
it add the spam class and removes the reported_spam class.
But I want to do Step2 without refreshing the browser.
Any help is appreciated.
Thanks,
Amit