title: In codeigniter How to redirect after login using ajax
body: <p>I have a login popup Modal. and i am logging through ajax</p>
  
  <p><strong>Modal</strong></p>
  
  <pre><code>&lt;div class="modal-body"&gt;
                &lt;form action="&lt;?php echo base_url('Login');?&gt;" method="POST"&gt;
                   &lt;div class="form-group"&gt;
                      &lt;input type="text" placeholder="Email or Mobile*" value="" id="loginEmail" name="email" class="form-control input-feild"&gt;
  
                   &lt;/div&gt;
                   &lt;div class="form-group"&gt;
                      &lt;input type="password" placeholder="Password*" value="" id="loginPassword" name="password" class="form-control input-feild"&gt;
  
                   &lt;/div&gt;
                   &lt;div class="form-group"&gt;
                      &lt;input type="button" id="l_submit" name="l_submit" value="Login" class="btn btn-primary input-feild"&gt;
                   &lt;/div&gt;
                 &lt;/form&gt;
                 &lt;p id="error-msg"&gt;&lt;/p&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>I am trying to redirect after successful login using ajax. If email and password is correct then redirect to any page. If not then it will show the Error. </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>function index() {
  
          $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required');
  
          if ($this-&gt;form_validation-&gt;run() == false) {
              echo validation_errors();
  
          }else {
                  $email      = $this-&gt;input-&gt;post("email");
                  $password   = $this-&gt;input-&gt;post("password");
                  $user = $this-&gt;Perfect_mdl-&gt;check_user($email, $password);
                  if ($user) {
  
                      $logged_in_data = array();
                      foreach ($user as $logged_in_data) {
                          $logged_in_data = array(
  
                                      'id' =&gt; $user[0]-&gt;id,
                                      'email' =&gt; $user[0]-&gt;email
                                  );
                      }
  
                      $this-&gt;session-&gt;set_userdata($logged_in_data);
                      $id = $this-&gt;session-&gt;userdata('email');
                      $data['details'] = $this-&gt;Perfect_mdl-&gt;get_login_user_detail($id);
  
                      echo "Yes";
  
                  }else {
  
                      echo "No";
                  }
          }
      }
  </code></pre>
  
  <p>This is my controller in which i am checking login user email and password correct/incorrect.</p>
  
  <p>This is my script</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;  
          $("#l_submit").click(function(){
  
              var email  = $("#loginEmail").val();
              var password   = $("#loginPassword").val();
  
              $.ajax({
                  url : "&lt;?php echo base_url('Login');?&gt;", 
                  type: 'POST',
                  data : {'email':email,'password':password},
                  success: function(msg) {
  
                          if (msg == "Yes")
                             window.location.href = "&lt;?php echo current_url(); ?&gt;";
                          else if (msg == "No")
                              $('#error-msg').html('&lt;div class="alert alert-danger text-center"&gt;Incorrect Email &amp; Password. Please try again ...&lt;/div&gt;');
                          else
                              $('#error-msg').html('&lt;div class="alert alert-danger"&gt;' + msg + '&lt;/div&gt;');
                      }
              });
              return false;
          });
  &lt;/script&gt;
  </code></pre>
  
  <p>As you can see in the success part, when i entered the correct email/password. It is showing Yes. But i want to redirect another page, Why this is showing <strong>YES</strong> on correct email/password.and On incorrect email/password This is showing <strong>NO</strong>.</p>
  
  <p>Where i am Doing Wrong???</p>