I have a problem with one jQuery script. I use this code:
<span class="follow" data-id="<?=$m['id']; ?>" ></span>
-
$('.follow').click(function(){
$.ajax({
type: "POST",
url:"../ajax/settings/follow.php",
async: false,
dataType:'html',
data: {'id':$(this).attr('data-id')},
success:function(rs){
$(this).removeClass("follow");
$(this).addClass("unfollow");
},
error:function (xhr, ajaxOptions, thrownError){
alert("ERROR !!!");
alert(xhr.status);
alert(ajaxOptions);
alert(thrownError);
}
});
});
After click the span with style image TICK changed to CROSS, and changed attr class to unfollow. After click unfollow class must change to follow, but not working.
$('.unfollow').click(function(){
$.ajax({
type: "POST",
url:"../ajax/settings/follow.php",
async: false,
dataType:'html',
data: {'id':$(this).attr('data-id')},
success:function(rs){
$(this).removeClass("unfollow");
$(this).addClass("follow");
},
error:function (xhr, ajaxOptions, thrownError){
alert("ERROR !!!");
alert(xhr.status);
alert(ajaxOptions);
alert(thrownError);
}
});
});
What's wrong?
I apologize for my English!