Skip to content Skip to sidebar Skip to footer

Unable To Compare Two Strings In Javascript

I am trying two compare two strings in JavaScript. But I guess there is some problem while comparing. It doesn't show the results. if(ajaxRequest.readyState == 4){ var msg =

Solution 1:

You might want to check if there's any space before or after the "false" string that you return from the server. You can do it easily with this:

alert('"' + msg + '"');

If there is extra space, you can just do:

msg = msg.trim();

and then do your if statement

Solution 2:

Ensure that there is no white space around the word "false" with something like:

if( msg.match(/\s*false\s*/i) )

Post a Comment for "Unable To Compare Two Strings In Javascript"