jquery - CodeIgniter won't pass $data when loading via AJAX? -
i working on database-driven site want uri segments of links load corresponding data database. site running on codeigniter 2.1.4 jquery mobile loading pages via ajax. here example of urls.
site.com/browse (runs index function, loading list of artists)
site.com/browse/artist/album (runs artist function, passing third uri segment album parameter data model, loading list of artist's albums)
i understand how pass id url model load data , process data view. when calling index function of browse class, works should. able create list of artist. when calling artist function, uri segment being passed model , loading data, $data not seem passing view keep getting undefined variable error when trying display data.
get_data.php:
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class get_data extends ci_model { function getallartists() { $query = $this->db->query('select distinct artist data order artist'); if($query->num_rows() > 0) { foreach($query->result_array() $row){ $data[] = $row; } return $data; } } function getallalbums($artist) { //get artist uri segment $artist = urldecode($this->uri->segment(3)); $query = $this->db->query('select distinct album, artist data artist = "'.$artist.'" order album'); if($query->num_rows() > 0) { foreach($query->result_array() $row){ $data[] = $row; } return $data; } } }
browse controller:
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class browse extends ci_controller { public function index(){ //page data $data['title'] = 'site: browse'; $this->load->model('get_data'); $data['rows'] = $this->get_data->getallartists(); $rows = $this->data['rows']; //page views $this->load->view('t/header', $data); $this->load->view('p/browse', $data); $this->load->view('t/footer'); } public function artist($artist){ //url decode $artist = urldecode($artist); //page data $data['title'] = 'site: '.$artist; //load model , retrieve data database $this->load->model('get_data'); $this->data['rows'] = $this->get_data->getallalbums($artist); $rows = $this->data['rows']; //page views $this->load->view('t/header', $data); $this->load->view('p/artist', $data); $this->load->view('t/footer'); } public function album($album){ //page data $data['title'] = 'site: '.urldecode($album); //load model , retrieve data database $this->load->model('get_data'); $this->data['rows'] = $this->get_data->getallsongs($album); $rows = $this->data['rows']; //page views $this->load->view('t/header', $data); $this->load->view('p/artist', $data); $this->load->view('t/footer'); } }
browse view (this works should):
<!-- start content.php --> <div data-role="page"> <div data-role="header" data-id="header" data-position="fixed"> <div data-role="navbar"> <ul> <li><a href="http://www.site.com/home" class="" data-transition="fade">home</a></li> <li><a href="http://www.site.com/browse" class="" data-transition="fade">browse</a></li> <li><a href="http://www.site.com/about" class="" data-transition="fade">about</a></li> <li><a href="javascript:void(0)"id ="toggle">▶</a></li> </ul> </div> </div><!-- /jqm-header --> <div data-role="content"> <ul id="song_list" data-role="listview" data-filter="true"> <?php foreach ($rows $r) {?><li data-icon="false"><a data-transition="slide" href="http://www.site.com/browse/artist/<?php echo urlencode($r['artist']); ?>"><?php echo $r['artist']; ?></a></li><?php };?> </ul> </div> <div data-role="footer"> <h4>site.com</h4> <h5><?php echo $this->benchmark->elapsed_time();?></h5> </div><!-- /jqm-footer -->
artist view (this gives me error: undefined variable "rows"):
<!-- start content.php --> <div data-role="page"> <div data-role="header" data-id="header" data-position="fixed"> <div data-role="navbar"> <ul> <li><a href="http://www.site.com/home" class="" data-transition="fade">home</a></li> <li><a href="http://www.site.com/browse" class="" data-transition="fade">browse</a></li> <li><a href="http://www.site.com/about" class="" data-transition="fade">about</a></li> <li><a href="javascript:void(0)"id ="toggle">▶</a></li> </ul> </div> </div><!-- /jqm-header --> <div data-role="content"> <ul id="song_list" data-role="listview" data-filter="true"> <li data-icon="false"><a data-rel="back">back</a></li> <?php foreach ($rows $r) {?><li data-icon="false"><a data-transition="slide" href="http://www.site.com/browse/album/<?php echo urlencode($r['album']); ?>"><?php echo $r['album']; ?></a></li><?php };?> </ul> </div> <div data-role="footer"> <h4>site.com</h4> <h5><?php echo $this->benchmark->elapsed_time();?></h5> </div><!-- /jqm-footer -->
this has been driving me insane. had working before , don't know problem is. have disabled jquery mobile ajax loading , still gives me error. appreciated. thanks.
Comments
Post a Comment