title: How to redirect on a successful AJAX form submission (PHP - CodeIgniter)
body: <p>I have a registration form that is being sent to the controller for validations, it is being sent back to the view page with <code>json encode();</code> on the view page this is my script for ajax:</p>
  
  <pre><code>$('#register_form').submit(function(){
      $.post(    
          $(this).attr('action'),
          $(this).serialize(),
          function(data){
              $('.prev_message').parent('div').removeClass('field_block');
              $('.prev_message').html('');
              if(data.register_error)
              {
                  $('#messages_register_error').html(data.register_error);
              }
              if(data.email)
              {
                  $('#messages_email').parent('div').addClass('field_block');
                  $('#messages_email').html(data.email);
              }
              if(data.first_name)
              {
                  $('#messages_first_name').parent('div').addClass('field_block');
                  $('#messages_first_name').html(data.first_name);
              }
              if(data.last_name)
              {
                  $('#messages_last_name').parent('div').addClass('field_block');
                  $('#messages_last_name').html(data.last_name);
              }
              if(data.password)
              {
                  $('#messages_password').parent('div').addClass('field_block');
                  $('#messages_password').html(data.password);
              }
              if(data.confirm_password)
              {
                  $('#messages_confirm_password').parent('div').addClass('field_block');
                  $('#messages_confirm_password').html(data.confirm_password);
              } 
              // if(data.link)
              // {
                  // return true;
              // }
          },                    
          "json"        
      );
      return false;
  });
  </code></pre>
  
  <p>I would like to know how I can have the page redirect to another page if there are no errors returned from the controller. This is the part of code in the controller that is supposed to redirect to another page on successful submission:</p>
  
  <pre><code>if($this-&gt;logged_user_info-&gt;user_status != 'admin')
  {
      //set the dashboard link to user_dashboard
      $this-&gt;page['dashboard_link'] = "/ci/dashboard";
      $this-&gt;session-&gt;set_userdata('dashboard_link', $this-&gt;page['dashboard_link']);
      //go to user_dashboard function which will login user and display user dashboard info
      // $dashboard_link['link'] = 'success';
      // var_dump($dashboard_link);
      // die();
      // echo json_encode($dashboard_link);
  
      // redirect(base_url('/dashboard'));
      header('Location: user_dashboard');
  }
  </code></pre>
  
  <p>Right now all that happens when I submit the form successfully - it stays on the register view page, and when I inspect element I notice that it is going to the dashboard page but only in the inspect element section not on the view page. (I have a feeling it has to do with the fact that in my ajax code it says <code>return false;</code>) I am just not sure how to go about that it should only "return false" when there are errors?</p>
  
  <p>(The commented out code is the code I was trying to insert to fix this problem, by sending back to the view page a message for success but then I was still having trouble making that the ajax code should redirect to a second view page on success message returned.)</p>