0

My return values are not working, and I am trying to validate login before form submit. I just can't put my finger on it.

function checklogin()
{
   var name=$('input[name=username]').val();
   var name=name.trim();
   var pass=$('input[name=password]').val();
   var pass=pass.trim();
   if(name == '')
   {
       return false;
   }
   else
   {
     $.ajax({
           type: 'post',
           url: 'checklogin.php',
           data: {
           user_name:name,
           user_pass:pass,
           },
           success: function (response) {

              if(response=="OK")    
              {
                // document.getElementById('error').innerHTML=" User pass test ok.";
                console.log("Hooray, it worked!");  
                 return true;   

              }
              else
              {
                 document.getElementById('error').innerHTML=" Invalid Email or Password.";
                 console.log("Nope... not working! "+name);
                 return false;  

              }

            } 
          });


   }          
}

I did all kinds of tests and all script work but the this part just act like it always return true. it seems the Ajax part is my problem.

  • It looks like you're only handling the `success` method of the ajax call. Have you tried also hooking into the `error` method ? – Himmel May 09 '16 at 04:13
  • 1
    Try debugging your JS code and find out if it really hits `success` function and also what is the value of response. – Ramin May 09 '16 at 04:29

0 Answers0