I am retrieving data that displays a value of true in the console, but when I set up an if statement
i开发者_JS百科f (onLive == true) {
alert ("is working")
}
the alert does not fire. Can anyone help me? Here is the code http://jsfiddle.net/8j947/
isLive
is "true"
(a string containing the word true
), not true
(a boolean value).
Works like this: http://jsfiddle.net/8j947/3/
You forgot to insert jQuery. And isLive returns 'true' a string, not a boolean! You can check it like this:
if (isLive == 'true') {
alert('working');
}
the var isLive specifically needs to compare boolean values. In this case, you might want to check what type it is comparing. I am quite sure that it is not a bool comparison. Secondly, as previously mentioned, the statement can be if(isLive=='true') { .... } Hope This Helps
精彩评论