Looking for ?

Translate

Solution -My Ajax Response Code Always Go In The Else Part (Programming)

  Solution -My Ajax Response Code Always Go In The Else Part.

Your Likely Question: I am stuck with ajax response, that always go in else part and it print no in session's class called statusmsg and also add meta tag. It is fine in localhost but not in live site.



SOLUTION

Always make sure your trim your response before using it in if statement

E.g


 $.ajax({             
                    type: "POST",  
                    url:"scripts/ajax_login.php",  
                    data:"account="+account+"&pswd="+password,

                    beforeSend: function()
                    {
                        $(".login_result").show();
                    },
                    success: function(resp)
                    {  

                        if($.trim(resp) == 'no')
                        {   
                            $(".warn_msg").html("Wrong Username/Email And/or Passwrd");
                            return false;                               
                        }
                        else
                        {   
                            $(".statusmsg").html("Welcome "+$.trim(resp));
                            $(".loginArea").hide();
                            $(".sh_logout").show();                                                     
                        }
                    }, 

                    complete: function()
                    {
                        $(".login_result").hide();
                    },

                    error: function(e)
                    {  
                    alert('Error: ' + e);  
                    }  

               }); //end Ajax   

                   }//else   
              return true;
               }//function


SHARE THIS POST

About Wakabia

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment