php - codeigniter send id and get database values without refresh
500
I need to send id and get database values according to the id without page refresh.and display data in my view,
here is my view,
<div>
<a href="javascript:void(0);" class="movie" onclick="getSummary(24)">Click on me</a>
</div>
<script type="text/javascript">
function getSummary(id)
{
$.ajax({
type: "POST",
url: '<?php echo site_url('ajax_controller/getBranchDetails'); ?>',
cache:false,
data: "id=" + id, // appears as $_GET['id'] @ ur backend side
success: function(data) {
// data is ur summary
$('#summary').html(data);
}
});
}
</script>
controller
public function getBranchDetails(){
$b_id = $this->input->post('branch_id');
$this->load->model('ajax_model');
$data['results'] = $this->ajax_model->getRecords($b_id);
//echo json_encode(array('data'=>$data));
}
I need to display $data['results'] in my view
model
<?php
class Ajax_model extends CI_model{
function getRecords($id)
{
$this->load->database();
$query = $this->db->query("SELECT * FROM companydetails WHERE id='$id'");
return $query->result();
}
}
Answer
Solution:
Try this code ,It is working .
Note : Check whether you have included jquery.min.js . If not mention the below code in view part header
Answer
Solution:
Try this instead:
Model: (Don't directly use variables inside the query string)
Controller: