I have a form that I submit to a php file, the php file will check if the record exists or not. If it exists it will echo "Already Exists". In my ajax "success" it does see the "Already Exist" but when I place a condition it does not work. For example under success in my ajax function I placed the following
$.ajax({
type: "GET",
data: $('#minifrm').serialize(),
url: "CRUD/myfile.php?check=" + para + "&freq=" + freq + "&expire=" + expire,
success: function (status) {
if (status.success == false) {
alert("Your details we not saved");
} else {
var checkstatus = status.toString();
if (checkstatus === 'Already Exists')
{
alert("You are here");
}
if (checkstatus === '')
{
alert("There is nothing");
}
}
}
});
Currently it will echo "Already Exists" and alert "You are here" but if it doesn't exist it will not alert "There is nothing".
Use double equal to ==
instead of single =
for comparing two variable like this :
if(checkstatus == 'Already Exists')
{
alert("You are here");
}
You used single equal to = means it will assign that value in variable in this way you will not get desired output currently in your case what happen when code execute if condition executed it will assign 'Already Exists' in checkstatus variable. So used Use double equal to ==. write your condition check code like below.
if (checkstatus == 'Already Exists')
{
alert("You are here");
}
if (checkstatus == 0)
{
alert("There is nothing");
}