0

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+"| &nbsp;"+response[curlen-1].Category+"| &nbsp;"+response[curlen-1].Amount+"| &nbsp;"+response[curlen-1].Comments+"| &nbsp;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);
}
4

0 回答 0