1
I have a simple ajax:
$.ajax({
url:"php/exemplo.php",
type:"POST",
data:new FormData(this),
contentType:false,
cache:false,
processData:false,
success: function(resposta){
if(resposta == '<nome>'){
alert('deu certo');
}
}});
In PHP I give a echo "<nome>";
and that <nome>
arrives at the right ajax (checked with an Alert)... but the if does not understand that is <nome>
, does not fall inside the if...
What can be the mistake?
What gives
console.log(typeof resposta, resposta && resposta.length, resposta);
?– Sergio
Maybe you have space, use the function
trim()
php– GeekSilva
Put PHP, always follow the MCVE (How to create a Minimal, Complete and Verifiable example): https://answall.com/help/mcve
– Guilherme Nascimento
PHP is just an echo "name";
– caiocafardo
@Geeksilva with Trim would do so? echo Trim("<name>");? If it is, did not give also....
– caiocafardo
@Sergio really gave this console.log 8.. and not 6 as it should
– caiocafardo
@ok caiocafardo, so it has blank spaces I presume or line breaks. It tests like this:
if(resposta.trim() == '<nome>'){
. If not, put the exact console.log result I asked for on top.– Sergio