简体   繁体   中英

load codeigniter view Via ajax

hi i'm creating an application in codeigniter. My problem is that i want to load page content dynamically via ajax like this:

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

Here is my codeigniter template loadview function:

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. 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. Like this ::

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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