我的代码是
<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);
}
});
});
我的控制器是
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);
}