I have a problem with my ajax, it can't display data from database.
Controller
public function rating() {
$rating = $this->db->select_avg('hasil_rating')
->get('tb_rating')->row_array();
echo json_encode($rating);
}
Ajax
function rate() {
$.ajax({
type: 'POST',
url: '<?php echo base_url()."rate/rating"?>',
dataType: 'json',
success: function(data) {
$('#aaaa').val(data);
}
});
input
<input id="aaaa" type="text" value="">
when I used val()
the result is [object Object] and when I used html()
the result is empty. But when I use console.log(data)
it works.