javascript - Update data using AJAX and codeigniter failed -
i want update data using codeigniter , ajax submit response..
this view
<form id="form_update" action="<?php echo base_url() ?>admin/update_derap_info" method="post" role="form"> <textarea cols="80" id="editor1" name="isi" rows="10" class="form-control" > </textarea> <input type="submit" value="simpan" class="btn btn-sm btn-primary" name="update_info_pemesanan"> </form>
my controller
$data = array ( 'isi'=> ltrim(rtrim($this->input->post('isi'))) ); $this->info_derap->update($this->input->post('id_info'),$data); echo'<div class="alert alert-success">terimakasih, pesan anda sudah kami terima. pemberitahuan selanjutnya kami beritahunak lewat email.</div>'; exit;
my model
function update($id,$data){ $this->db->where($this->id, $id); $this->db->update($this->table, $data); }
and here ajax
<script type="text/javascript"> $("#form_update").submit(function (e){ e.preventdefault(); $("#loader").show(); var url = $(this).attr('action'); var data = $(this).serialize(); $.ajax({ url:url, type:'post', data:$("#form_update").serialize(), }).done(function (data){ $("#response").html(data); $("#loader").hide(); fillgrid(); }); }); </script>
i can update data if press click submit 2 times, when submit 1 time , cannot update.
what's wrong?
you cant update form. use this
<form action="" method="" role="form"> <textarea cols="80" id="editor1" name="isi" rows="10" class="form-control" ></textarea> <input type="submit" value="simpan" class="btn btn-sm btn-primary" name="update_info_pemesanan" id="form_update"> </form>
in ajax
<script type="text/javascript"> $(function(){ $("#form_update").click(function(event){ event.preventdefault(); $("#loader").show(); var editor1= $("#editor1").val(); $.ajax( { type:'post', url:"<?php echo base_url() ?>admin/update_derap_info", data:{editor1:editor1}, success:function($data) { $("#response").html(data); $("#loader").hide(); fillgrid(); } }); }); }); </script>
in controller
$text_area = $this->input->post('editor1')
so in $text_area
contain text input in form
Comments
Post a Comment