I’m trying incorporate some if-else statements with ajax
So basically I have this php file get.php and another php file (with the ajax code) ajax.php
my ajax looks something like this. This is ajax.php
$.ajax({
type: "GET",
data: data,
url: "get.php"
}).done(function(data){
alert(data);
if(data == "homer"){
alert("doh");
}else if(data == "wife"){
alert("marge");
}
});
I have some php script, this is get.php
if(!$something){
echo "homer";
}else{
echo "wife";
}
So basically, I’m getting the appropriate alert(data), which is either homer or wife. But its not alerting doh or marge
Can someone explain why this is not working?
Thank you!
http adds some white spaces to the data so you have to trim it first
if else route on ajax data not working