如何在div中加载视图 - codeigniter

zes*_*lva 3 load codeigniter view

我有一个页面,我想保持静态与两个div,我想在用户导航期间加载不同的HTML视图.我希望更改内容而不刷新整个页面,只刷新这两个div.

如何将特定视图加载到这些div中?我已经有菜单导航,确定要加载到这些div和控制器功能的html视图到我使用javascript获得的菜单选项,然后在主页的控制器中使用它,我只是不知道如何加载内容.

Cal*_*vin 5

您可以使用一些Javascript和AJAX加载视图.

使用jQuery:

$('a.nav-button').click(function(e) {
  // prevent the default action when a nav button link is clicked
  e.preventDefault();

  // ajax query to retrieve the HTML view without refreshing the page.
  $.ajax({
    type: 'get',
    url: '/path/to/your/controller/method',
    dataType: 'html',
    success: function (html) {
      // success callback -- replace the div's innerHTML with
      // the response from the server.
      $('#yourDiv').html(html);
    }
  });
});
Run Code Online (Sandbox Code Playgroud)