window.location.href don't work with AJAX
<p>For some reason, the &quot;<strong>window.location.href</strong>&quot; function does not work for me, can't seem to find out why.
<strong>This is the code from index.php:</strong></p>
<pre><code>&lt;div class=&quot;dropdown-menu&quot;&gt;
    &lt;div style=&quot;width: 300px;&quot;&gt;
        &lt;div class=&quot;panel panel-primary&quot;&gt;
            &lt;div class=&quot;panel-heading&quot;&gt;Login&lt;/div&gt;
            &lt;div class=&quot;panel-heading&quot;&gt;
                &lt;label for=&quot;email&quot;&gt;Email&lt;/label&gt;
                &lt;input class=&quot;form-control&quot; id=&quot;email&quot;  name=&quot;email&quot; required /&gt;
                &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
                &lt;input type=&quot;password&quot; class=&quot;form-control&quot; id=&quot;password&quot;  name=&quot;password&quot; required /&gt;
                &lt;p&gt;&lt;br/&gt;&lt;/p&gt;
                &lt;a href=&quot;#&quot;&gt;Forgotten Password&lt;/a&gt;&lt;input type=&quot;button&quot; class=&quot;btn btn-success&quot; name=&quot;login&quot; id=&quot;login&quot; value=&quot;Login&quot;&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;panel-footer&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p><strong>And this is the function in the &quot;action.php&quot; file that is mentioned in the jQuery function:</strong></p>
<pre><code>&lt;?php
if(isset($_POST[&quot;userLogin&quot;])){
    $email = mysqli_real_escape_string($con, $_POST[&quot;userEmail&quot;]);
    $password = md5($_POST[&quot;userPassword&quot;]);
    $sql = &quot;SELECT * FROM user_info WHERE email = '$email' AND password = '$password'&quot;;
    $run_query = mysqli_query($con, $sql);

    if($run_query===false){
        echo mysqli_error($con);
    } else {
        $row = mysqli_fetch_array($run_query);
        $_SESSION[&quot;uid&quot;]= $row[&quot;user_id&quot;];
        $_SESSION[&quot;name&quot;]= $row[&quot;first_name&quot;];
        echo &quot;welcome&quot;;
    }
}
?&gt;
</code></pre>
<p><strong>This is the jQuery with the AJAX function:</strong></p>
<pre><code>$(document).ready(function(){
    $(&quot;#login&quot;).click(function(event){
        event.preventDefault();
        var email =  $(&quot;#email&quot;).val();
        var pass = $(&quot;#password&quot;).val();
        
        $.ajax({
            url : &quot;action.php&quot;,
            method : &quot;POST&quot;,
            data : {userLogin: 1, userEmail:email, userPassword:pass},
            success : function(data){
                if(data == &quot;welcome&quot;){
                    window.location.href = &quot;profile.php&quot;;
                }
               /* alert(data);*/
            }
        });
    });
});
</code></pre>
<p><strong>notes:</strong>
As you can see in the jQuery function, there is this: &quot;alert(data);&quot;. I wanted to look if it does work and put it on the screen without the &quot;window.location.href&quot; function to see that the &quot;if&quot; statement is correct, and it does work. Further more, when I go directly to the profile.php file, I see That the user is logged in, which means for me that the SQL functions is working fine, just it will not Re-Direct me to that (profile.php) page.</p>