Reputation: 10929
I have this:
$(document).ready(function() {
$.get('getturn.php', function(data){
if (data!=='4') { alert (' change'); }
if (data=='4') { alert ('no change');}
});
});
getturn.php echoes 4 if the turn is equal to a session id, and it echoes the turn number if otherwise. The getturn.php does as it should, it echoes 4 or a number like 0,1,2,3; however when I get the data like seen above from a different file, and check if it equals to 4, I can't get the correct answer... What am I doing wrong? I thought we could check if the output was yes with data=='yes' ? but we can't check numbers with data=='4'?
Upvotes: 1
Views: 193
Reputation: 16951
if understand your problem correctly, this will help:
data = parseInt(data);
if (!isNaN(data)) {
if (data != 4) { ... }
if (data == 4) { ... }
}
just convert "data" variable to numeric value(e.g. integer in this case)
Upvotes: 1
Reputation: 38526
Have you done an alert(data);
to see what is returned?
I think you should try this slight modification:
if (data == '4') { alert ('no change');}
else { alert (' change'); }
Based on this answer: How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?
Upvotes: 2