davidb
davidb

Reputation: 1603

PHP Ajax - success function if

I'm having difficulty getting ajax success function to differentiate the results that come in.

$.ajax(
{
    type: "POST",
    url: '../ajax/ajaxLogin.php',
    data: { "username": loginUsername, "password": loginPass },
    success: function (loggedIn)
       {
           if(loggedIn == "OK") 
              {
                 window.location = 'index.php';
              } else 
              {
                 alert(loggedIn);
              }
       }
});

When user credentials are correct then php sends "OK" to ajax and the user should be redirected to index.php. The result I get is always an alert. I get "OK" in alert windows as well as other messages. Whatever happens I always get something in alert window and never get redirected. What might be wrong here?

Upvotes: 0

Views: 57

Answers (1)

Sarath Kumar
Sarath Kumar

Reputation: 1146

try if(loggedIn.trim() == "OK")

Upvotes: 1

Related Questions