简体   繁体   English

通过ajax加载codeigniter视图

[英]load codeigniter view Via ajax

hi i'm creating an application in codeigniter. 嗨,我在codeigniter中创建一个应用程序。 My problem is that i want to load page content dynamically via ajax like this: 我的问题是我想像这样通过ajax动态加载页面内容:

$.ajax({
    url:'/customer/customerList',
    type: 'POST',
    dataType: 'text',
    success: function(data) {
        $('#container').empty().append(data)
    }
});

Here is my codeigniter template loadview function: 这是我的codeigniter模板的loadview函数:

function loadView($page, $data = NULL) {

    $parts = array('header', 'menu-top', 'sidebar-menu', $page, 'footer');

    foreach($parts as $part) {

        if ($part == 'header') {

            $this -> CI -> load -> view($part, $data);
        } else

        if ($part == 'menu-top') {
            $data['menu'] = $this -> loadMenu('menu-top');
            $this -> CI -> load -> view($part, $data);
        } else

        if ($part == 'sidebar-menu') {
            $data['menu'] = $this -> loadMenu('sidebar-menu');
            $data['controller_name'] = $this -> CI -> uri -> segment(1);
            $data['function_name'] = $this -> CI -> uri -> segment(3);
            $this -> CI -> load -> view($part, $data);
        } else

        if ($part == $page) {
            $this -> CI -> load -> view($part, $data);
        } else
        if ($part == 'footer') {
            $this -> CI -> load -> view($part, $data);
        }
    }
}

I use that template for static menu(no reloading). 我将该模板用于静态菜单(无需重新加载)。

But when i load controller/view with ajax it return all the html, because of this template. 但是当我使用ajax加载控制器/视图时,由于此模板,它会返回所有html。 Is there any option to resolve this solution? 有什么解决方案吗?

How to chanhe template to always have static sidebar menu, and load only middle of the application. 如何更改模板以始终具有静态侧边栏菜单,并仅在应用程序的中间加载。

Thanks for replay. 感谢您的重播。

You should send a false value as a third parameter to get return data and print that data not loading the HTML file. 您应该发送错误值作为第三个参数,以获取返回数据并打印未加载HTML文件的数据。 Like this :: 像这样 ::

echo $this->CI->load->view($part, $data, FALSE); 回声$ this-> CI-> load-> view($ part,$ data,FALSE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM