i new codeigniter , created function update data using jquery ajax function below. working on admin page(content management system). problem data not inserting/updating on model. hope me on this.
view file:
$('.ds_tpi_save').click(function () { var pid = $('.mychange').val(); var tpi = $('.datatpi').val(); $.ajax({ url: '<?php echo site_url('admin/ajax_update'); ?>', type: 'post', datatype: 'html', data: {id: pid, tpi: tpi}, success: function (a) { if (a == 'success') { $('#editcontent').modal('hide'); $('.mychange').val(''); $('.datatpi').val(''); location.reload(); } } }); }); });
controller file:
public function ajax_update(){ $pid = $this->input->post('id'); $ptpi = $this->input->post('tpi'); $update = $this->products_model->ajax_update($pid,$ptpi); var_dump($update); // bool(false) fail (to insert database) echo ($update)?'success':'fail'; }
model file:
function ajax_update($pid,$ptpi){ $data = array( 'package_includes' => $ptpi, ); $this->db->where('id',$pid); $this->db->update('products',$data); // return ($this->db->affected_rows()>0)?true:false; return $this->db->affected_rows() > 0; }
header:
request admin/ajax_update, ,request method:post ,status code:200 ok