In the code below, the script suggest.php will return “Fail1” if the passed value s is blank. It will return “Fail2” if the user is not logged in, and it will return “Suggestion” if everything worked as it should.
Now, if the user is not logged in and tries to submit a suggestion, I have been getting the alert(“You must have an account to add new Suggestions !”) TWICE.
I can’t figure out why . The sequence of readyStates is:
1,
2,
3,
4, – Get the message here
1 – Get the message again, HUH??
function addsuggest(s,c) {
var url = "suggest.php?suggession="+s+"&catid="+c;
var xmlHttp = getXMLHttp();
try {
xmlHttp.onreadystatechange = function() {
alert(xmlHttp.readyState);
if (xmlHttp.readyState == 4) {
msg = xmlHttp.responseText;
if(msg == "Suggestion") {
alert("Suggestion posted successfully....");
return true;
}
if(msg == "Fail1") {
alert("Suggestion Text was blank?");
msg = '';
return false;
}
if(msg == "Fail2") {
alert("You must have an account to add new Suggestions !");
msg = '';
return false;
}
}
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
catch(err) {
alert(err);
}
}
Any ideas as to why this is happening?