Ajax调用总是运行成功函数

i want to verify user_id and mobile number from server (php) . when i enter wrong user_id and mobile number so every time ajax is execute success (if) part rather than else part.

my ajax is

         <script>
          $(document).ready(function() {
          $("#b").click(function(){
          var user_id=$('#user_id').val();
          var mobile=$("#mobile").val();
                    $.ajax({
                            type:"POST",
                            url:"http://localhost/test.php",
                            data:{user_id:user_id, mobile:mobile},
                              success:function(response){
                                if(response="valid"){
                                    alert(response);
                                    window.location='https://www.google.co.in';
                                }
                                else{
                                    alert("invalid");
                                }                       

                              },
                              error:function(response){
                                alert("error");
                              }
                          });       

                });  
              });

</script>

my php code

 <?php
  $user_id=$_POST['user_id'];
  $mobile=$_POST['mobile'];
  $con=@mysql_connect("localhost","root","")or die('connection failed: ' . mysql_error());
  $db=mysql_select_db("sorethroat");  
  $result = mysql_query("SELECT * FROM `myfieldmembers` where `employee_id`='".$user_id."' && `mobile`='".$mobile."'");
    if($result === FALSE) { 
        die(mysql_error()); // TODO: better error handling
    }
    if(mysql_num_rows ($result)>0) {
      echo "valid";
    } else {
      echo"invalid";
    }

 ?>

on server side after hard-code this php is working fine

response="valid" change to response=="valid"

You have solved it by replacing valid/invalid with 1/0, so it is working now.

For people who run into the same problem and are not able to replace with 0/1:

Check the length of the response. Sometimes spaces get added, in that case your when checking values on screen it will look like you are comparing "phrase" == "phrase" but your code will compare "phrase" == " phrase" (notice the space), which is not the same.

After having had to deal with this problem myself, I am using this by default

response = response.trim();