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,

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.