I am screwed with this one the if statement is not working in javascript. I am using js to call php and php file echo 'true';
My java script code
function like_add(article_id){
$.post('my/like.php', {article_id:article_id}, function(data){
if(data == 'true'){//this part never works
alert(data);
}else{
alert(data);
}
});
}
I tried to change alert with alert('*'+data+'*');
And got that there is a space * true*. How can I get this script t work.
Whole code
function like_add(article_id){
$.post('ajax/like.php', {article_id:article_id}, function(data){
if(data == 'true'){
total_votes(article_id);
}else{
alert(data);
}
});
} PHP code
if(previously_liked($article_id) === true){
echo 'You\'ve already liked this!';
}else{
add_like($article_id);
echo 'true';
}
function total_votes(article_id){
$.post('ajax/total_votes.php', {article_id:article_id}, function(data){
$('#article_'+article_id).text(data);
}); }
else?alert(typeof data)before theifstatement.if($.trim(data) == 'true') {