jemz
July 12, 2013, 9:09pm
1
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');
}
});
jemz:
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
$.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?
jemz
July 12, 2013, 9:42pm
3
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?
jemz
July 12, 2013, 10:26pm
5
I already, tried console.log “success” but it always falls to else statement…I am confuse with this…
jemz
July 12, 2013, 10:32pm
6
is there other way to check if this string contains whitespace or something…?
jemz
July 12, 2013, 10:39pm
7
Jeff_Mott:
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 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…
jemz:
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!
jemz
July 12, 2013, 11:11pm
9
paul_wilkins:
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…