My code is
<script>
$("#saveExpense").click(function(){
alert('I am in jquery function');
$.ajax({
type:'GET',
url: "<?php echo site_url('expenses/addExpense');?>",
dataType: 'json',
data:$('#AddExpenseForm').serialize(),
success: function(response) {
comsole.log(response);
var curlen = response.length;
var htm = curlen+"| "+response[curlen-1].Category+"| "+response[curlen-1].Amount+"| "+response[curlen-1].Comments+"| Edit/Delete<br />";
$("#ShowExpenses").append(htm);
}
});
});
My controller is
function addExpense(){
if(!$this->session->userdata('logged_in'))
redirect('expenses','refresh');
$this->expenses_model->addExpense();
$data=$this->expenses_model->viewExpenses();
echo json_encode($data,TRUE);
}