the jquery
$(document).on('click', '#fun', function (e) {
var $this = $(this);
var request = $.ajax({
url: "example.php",
type: "POST",
data: {bla: blabla},
dataType: "html"
});
request.done(function(msg) {
if(msg)
{
$this.addClass("btn btn-info btn-small marked");
$("#isMarked", $this).val(msg)
}
else if(!msg)
{
$this.addClass("btn btn-small unmarked");
$("#isMarked", $this).val(msg);
}
});
and the button
<a id='fun' class='btn btn-info btn-small marked' href='#'>fun</a>
example.php will return a value either 0 or 1 (indicate true or false)
so the msg will be 0 or 1
the addClass in else if(!msg) can’t works. I can’t find the problem. any idea?
msgwill be a string so you are comparing a string in the if so it should always be true since a string is a truthy value.