内部和外部js文件在ajax调用后停止工作 - codeigniter

时间:2017-11-11 05:18:53

标签: javascript php jquery ajax codeigniter

所以我已经好几天了。所以每次我在div里面加载一个新的内容/视图时,会发生什么。内容不会从已经加载到我的核心控制器上的footer.php获取JS。这是示例代码。

JS

$(function() {
$(document).on("click", "a[rel=tab]", function(e) {
    // e.preventDefault();
    pageurl = $(this).attr('href');
    $.ajax({
        url: pageurl + '?rel=tab',
        success: function(data) {
            $('#inside').html(data);
        }
    });

    //to change the browser URL to 'pageurl'
    if (pageurl != window.location) {
        window.history.pushState({ path: pageurl }, '', pageurl);
    }
    return false;
});

$(window).bind('popstate', function() {
    $.ajax({
        url: location.pathname + '?rel=tab',
        success: function(data) {
            $('#inside').html(data);
        }
    });
});
});

在这里我已经加载了我的控制器和所有其他配置。所以我需要做的就是在它们之间加载已经有效的内容。唯一的问题是每次它正在工作它不会在新内容上加载任何JavaScript 的芯/控制器

class MY_Controller extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
$this->load->model('playlist_model');
$this->load->helper('url_helper');
$this->load->model('song_info_model');
$this->load->library('zip');
}

public function load_page($page,$data = null, $return = FALSE){

        $this->load->view($page, $data);
    } 


public function template($page,$data = null){

    $id = $this->session->userdata('user_id');
    $data['users'] = $this->user_model->get_users();
    $data['title'] = 'Users List';
    $playlist_id = $this->uri->segment(3);
    $data['folders'] = $this->playlist_model->get_folders();
    $data['playlists'] = $this->playlist_model->get_playlists();
    $data['user_folder'] = $this->playlist_model->get_playlist_by_user_id($id);
    $data['user_playlist'] = $this->playlist_model->get_playlist_by_folder();
    $data['playlist_title'] = $this->playlist_model->get_specific_playlist($playlist_id);
    $data['song_list'] = $this->playlist_model->get_songs_in_playlist($playlist_id);
    $data['session'] = $this->user_model->get_specific_user($id);
    if($this->session->has_userdata('user_email'))
    {
        $this->load->view('templates/header', $data);
        $this->load->view('templates/player', $data);
        $this->load->view('templates/modals', $data);
        $this->load->view('templates/content', $data);
        $this->load->view($page, $data);
        $this->load->view('templates/footer');
    }
    else{
      redirect('users/login');        
    }
}
}

控制器

class Dashboard extends MY_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$data = array();
$data['main_song_lists'] = $this->song_info_model->get_song_list();

$this->load_page('dashboard',$data);

}
}

0 个答案:

没有答案