echo json_encode($ data,TRUE)不会回到codeigniter中的ajax函数

时间:2013-04-09 07:48:40

标签: ajax codeigniter-2 json

我的代码是

<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); 
        }
    });
 });

我的控制器是

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);
}

0 个答案:

没有答案