How to check string equality inside inside of JQuery Ajax request's success block

I’m trying to check the value inside a condition statement after it comes back from the server, but it doesn’t seem to be working as expected. For debugging I’m checking the value with an alert statements and that value is what i’m expecting, but it doesn’t seem to work inside of the condition statement.


$.ajax({
  type: "POST",
  url: "scripts/process-step1.php",
  data: $('.home1').serialize(),
  success: function(msg){
      alert(msg); // remove after testing

      if (msg === 'Life' ){
          document.location.href = 'form-life.php';
      }
      else{
         document.location.href = 'form.php';
      }

  },

I have tried both


msg === 'Life'


msg == 'Life'

any ideas?

I am assuming that your alert already should you are getting the word Life ( capitalized) back from the AJAX request.
As a test , to make sure a String type object is begin returned I would do :
alert(typeof msg); // remove after testing

Now, assuming msg is a string, remember that there could be BLANK spaces begin returned as well so you will want to do a trim before testing: msg=msg.trim();

hope that helps

msg=msg.trim(); 

trim method fixed it. Thanks!!!