I am working on a web app where the user is asked to add an "application" by entering the StudentID and JobID. I am using jQuery to let the user know when a student that they entered doesn't exist, a job doesn't exist,the application already exists on the database or when the application has been added successfully. I check everything on the backend using PHP and send the message to the frontend to display that to the user. Everything works fine until the if-statement which I use to decide the message that I will display to the user based on the message received from the backend. jQuery completely ignores the 'else if' statements. If the first condition it true, it executes its body successfully, however, if the first one isn't true it goes straight to the else statement, ignoring the else if statements even if they are true. Here is the code:
var myData = {"tablename": tablename, "StudentId": StudentId, "JobId": JobId};
$.ajax({
url: "insert.php",
type: "POST",
data: myData,
success: function (data, status, xhr) {
console.log(data);
if (data =="success") {
$('#message').fadeIn().delay(3000).fadeOut();
$('#StudentId').val('');
$('#JobId').val('');
} else if(data=="fail") {
$('#message5').fadeIn().delay(3000).fadeOut();
} else if (data =="student"){
$('#message2').fadeIn().delay(3000).fadeOut();
}
else if (data == "job"){
$('#message3').fadeIn().delay(3000).fadeOut();
}
else (data == "studentjob") {
$('#message4').fadeIn().delay(3000).fadeOut();
}
}
});
Aucun commentaire:
Enregistrer un commentaire