title: getting an ajax response into an array then checking if that array has a specific value
body: <p>I have a simple php script which queries a database to find a username and password match, if a match is found it echos 'success' else it echos 'fail|Those details are incorrect, please check and try again.'</p>
  
  <p>I'm using ajax to trigger this function and perform an action based on the response data. The issue is that no matter what method i use, the if statement does nothing, though if i give a static value it works fine!! here are 3 of my 10,000 attempts:</p>
  
  <p>method 1 - always returns -1</p>
  
  <p>function userLogin(){
      $.post( sysFolder+'cmd.php?action=userLogin', $('#login').serialize(),
          function(data) {
              var arr = data.split('|');</p>
  
  <pre><code>        if($.inArray('fail',arr)){
              alert('no');
              //$('#login .msg').text(msg[1]).slideDown();
          }else if($.inArray('success',arr)){
              alert('yes');
              //window.location.href = homeFolder;
          }
      }
  );
  </code></pre>
  
  <p>}</p>
  
  <p>method 2 - arr[0] is recognised in an alert but if statements do not trigger</p>
  
  <p>function userLogin(){
      $.post( sysFolder+'cmd.php?action=userLogin', $('#login').serialize(),
          function(data) {
              var arr = data.split('|');</p>
  
  <pre><code>        if(arr[0] == 'fail'){
              alert('no');
              //$('#login .msg').text(msg[1]).slideDown();
          }else if(arr[0] == 'success'){
              alert('yes');
              //window.location.href = homeFolder;
          }
      }
  );
  </code></pre>
  
  <p>}</p>
  
  <p>method 3 - triggers the fail action perfectly but is obviously not reading the php/ajax response</p>
  
  <p>function userLogin(){
      $.post( sysFolder+'cmd.php?action=userLogin', $('#login').serialize(),
          function(data) {
              var arr = 'fail';</p>
  
  <pre><code>        if(arr[0] == 'fail'){
              alert('no');
              //$('#login .msg').text(msg[1]).slideDown();
          }else if(arr[0] == 'success'){
              alert('yes');
              //window.location.href = homeFolder;
          }
      }
  );
  </code></pre>
  
  <p>}</p>
  
  <p>here is a link to the current site which is currently trying to use method 2 as above <a href="http://57bit.com/admin/" rel="nofollow">http://57bit.com/admin/</a>
  PLEASE HELP!</p>