Why i could not compare this string

Hi, I am almost 4 hours debugging in this string,i could not compare this …
it always goes to my else statement but when i try to alert it is “success” but why it did not go to the if statement.please help me on this

Thank you in advance.


  $.ajax({
    type:'post',
    ....
    ...
    success:function(data){
      if( data == "success")
           alert('done');
      else
           alert(data + 'problem');
 }

});



What is the length of data? Is it more than 7 characters?

Yes, more than 7 …i tried to alert(data.length)…why is it more than 7?it should be 7 characters.

Try console.log instead of alert. data might not be a string.

EDIT: And continue to follow up with paul_wilkins’s thought process. Seems there might be some whitespace characters in there. A newline maybe?

I already, tried console.log “success” but it always falls to else statement…I am confuse with this…

is there other way to check if this string contains whitespace or something…?

I tried to use indexOf(‘\s’)>=0 then it alerted…so it means has whitespace,… but i check this where it came from it has no whitespace.

return “success” this is the string,i tried to retype.but it always fall to else statement…

If it comes from a PHP file, does the PHP file end with ?> followed by a newline? Anything after the ?> will be output too.


<?php
echo "success";
?>
Surprise!

Whoooo…thank you so much paul_wilkins…you solved my problem…now i know that if we put whitespace on this ?> end tag it will also output.

many regards…:slight_smile: