I have a default controller:
class Home extends CI_Controller {
public function index()
{
$data['content']='discover';
$this->load->view('layouts/master', $data);
}
public function categories()
{
$this->load->view('categories');
}
}
On click, using AJAX i was able to load the view categories.php and update the URL to www.mywebsite.com/categories without refreshing the page.
But now, if the user lands here directly using the link or refreshes the page he ends up loading only the categories.php view and not the master.php view
How do i load the master.php and categories.php view on direct URL navigation or page refresh
Just load categories.php when using AJAX.
My AJAX:
$('#navbar a').click(function(e){
e.preventDefault();
href=$(this).attr('href');
if (href.indexOf(document.domain) > -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);
}
});
};
Thanks!