title: Codeigniter- controller views using ajax and without
body: <p>I have a default controller:</p>
  
  <p>class Home extends CI_Controller {</p>
  
  <pre><code>public function index() 
  {   
      $data['content']='discover';
      $this-&gt;load-&gt;view('layouts/master', $data);             
  }   
  
  public function categories()
  {
      $this-&gt;load-&gt;view('categories');
  }
  </code></pre>
  
  <p>}</p>
  
  <p>On click, using AJAX i was able to load the view <em>categories.php</em> and update the URL to www.mywebsite.com/categories without refreshing the page.</p>
  
  <p>But now, if the user lands here directly using the link or refreshes the page he ends up loading only the <em>categories.php</em> view and not the <em>master.php</em> view</p>
  
  <ol>
  <li><p>How do i load the master.php and categories.php view on direct URL navigation or page refresh</p></li>
  <li><p>Just load categories.php when using AJAX.</p></li>
  </ol>
  
  <p>My AJAX:</p>
  
  <pre><code>$('#navbar a').click(function(e){
      e.preventDefault();
      href=$(this).attr('href');
      if (href.indexOf(document.domain) &gt; -1 || href.indexOf(':') === -1){
          window.history.pushState('obj', '', href);
          navigat(href);          
      }       
  });
  
  function navigat(href){             
      $.ajax({
          type:'GET',
          url:href,
          cache:false,
          dataType: 'html',
          statusCode: {
                  404: function() {
                    $("#content").html('Could not contact server.');
                  },
                  500: function() {
                    $("#content").html('A server-side error has occurred.');
                  }
          },
          error: function() {
              $("#content").html('A problem has occurred.');
          },
          success: function(html) {
              $('#content').html(html);
  
          }
      });     
  };
  </code></pre>
  
  <p>Thanks!</p>