0
Hello, I have following code:
function addUser(value){
var adduser = value;
var useremail = localStorage.getItem('email');
var userpassword = localStorage.getItem('password');
var acao = "adicionar";
$.post('http://localhost/app/searchplayer.php', {useremail : useremail, userpassword : userpassword, acao : acao, adduser : adduser}, function(retorna){
if(retorna == "sucesso2"){
alert (retorna);
}
});
}
and the php code I have a single echo that returns success2 (echo "success2";) but in the if condition of the script it does not return the Alert. If I just put Alert(returns); it returns the alert with the value success2 but with the condition if it does not return. Any idea of what might be?
Sorry, but what is the return value? How about putting a "}Else{Alert('what is the return value?')}; See what happens?
– MagicHat
Maybe it’s a space you have and can’t see. Try
if(retorna.trim() == "sucesso2") {....
– Miguel
@Magichat - It returns the echo value on a php page, which in this case is success2.
– rhundler
@Miguel tested with <code>if(returns.Trim() == "success2") {.... <code> and it worked. Now the question of being a space, apparently there is none. What would be the function . Trim()? thank you
– rhundler
The Trim function, present in several languages removes spaces present in the ends and uses string, whether spacing at the beginning or end of the string.
– Leonardo