echo json_encode($data,TRUE) is not going back to the ajax function in codeigniter -
my code is
<script> $("#saveexpense").click(function(){ alert('i 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
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); }
Comments
Post a Comment