Jump to content

alert(f) ALERTS "correct" BUT if(f=='correct') doesn't work!?


slj90

Recommended Posts

I don't understand why these if statements aren't working:

 $.post('./action/forgotpasswordcheck.php',{username:tu, email:te},function(f){
if(f=='correct') {
alert('Correct!')
} else if(f=='incorrect') {
 alert('Incorrect!') 
 } else {
 alert(f) }
  });
}

It alerts the last alert, alert(f) and it either says 'correct' or 'incorrect' so why aren't the if statements working?

 

forgotpasswordcheck.php contains:

if ($rowcount == 0) { echo "incorrect"; } else { echo "correct"; }

Thanks in advance,

Hi, thanks for your reply,

 

I've made the changes but now none of the javascript on the page is working.

 $.post('./action/forgotpasswordcheck.php',{username:tu, email:te},function(f){
if(f.status == 'correct'){
alert('Correct!')
if(f.status == 'incorrect'){
 alert('Incorrect!') 
 } else {
 alert(f) }
  });
}

Please advise,

 

Thanks,

Did you get this working?

 

If not, print the contents of f to your console and check it there. If the status isn't 'correct', but for instance, "you are correct, sir or ma'am!", then my code wont' work because it's checking equality. However, your code would work because the word 'correct' is present in the string somewhere after the first letter of the string. It's also possible that the JSON output from forgotpasswordcheck.php isn't being parsed in JavaScript before the check is made.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.