I’m attempting to following the tutorials found here: http://www.ifadey.com/2010/06/crud-using-jquery-and-codeigniter/ My code is updated to accomodate for CI and JQ updates. But when attempting to load data from my db and display it in my view, nothing happens/is displayed. All links to javascript (JQ) code work and everything is running locally using MAMP. Any and all help is greatly appreciated.
My code is as follows,
Model:
<?php
class mUsers extends CI_Model {
public function getAll() {
//get all records from users table
$this->db->_compile_select();
$query=$this->db->get('users')->result();
//OR $query = $this->db->get('users');
echo $this->db->last_query();
if( $query->num_rows() > 0 ) {
return $query->result();
} else {
return array();
}
} //end getAll
} //end class
?>
Controller:
<?php
class Site extends CI_Controller{
public function index(){
$this->load->model('mUsers');
$this->load->view('home');
}
public function read(){
header('Content-Type: application/json',true);
echo json_encode($this->mUsers->getAll());
}
}
?>
View:
<html>
<head>
<title>Test</title>
<base href="<?php echo base_url(); ?>" />
<link type="text/css" rel="stylesheet" href="css/styles.css" />
<link type="text/css" rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.12.custom.css" />
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#read">Read</a></li>
<li><a href="#create">Create</a></li>
</ul>
<div id="read">
<table id="records"></table>
</div>
<div id="create">Create form goes here...</div>
</div> <!-- end tabs -->
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.tmpl.js"></script>
<script type="text/template" id="readTemplate">
<tr>
<td>${id}</td>
<td>${name}</td>
<td>${email}</td>
</tr>
</script>
<script type="text/javascript" src="js/all.js"></script>
</body>
</html>
Finally figured it out. Ajax call should contain .tmpl, not .render: