dimanche 22 mars 2015

Issue with execution of multiple if and else if

I have a json data named "data" from an AJAX request and i am trying to configure it to display error messages. In the below code, the first two "if else" works except for the last one. :-(


But if i delete the first two "if else" statements, the third one works perfectly.



if (data.error === "error1") {
alert("error1");
} else if (data.error === "error2") {
alert("error2");
}

if (data.invalidAttributes.rule1 === "error3" ) {
alert("error3");
} else if (data.invalidAttributes.rule1 === "error4" ) {
alert("error4");
}

if (data.invalidAttributes.rule2 === "error5" ) {
alert("error5");
} else if (data.invalidAttributes.rule2 === "error6" ) {
alert("error6");
}

Aucun commentaire:

Enregistrer un commentaire