Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
Cara manggil function di href di ajax
Saya dapat masalah saat manggil function href di ajax saat mau menampilkan notify.js
Ini Codingnya:
View
<tbody>
<?php foreach ($rows as $row) { ?>
<tr>
<td><?php echo $row ->description ?></td>
<td><?php echo $row->updated_at ?></td>
<td><a href="<?php echo base_url().'admin/edittipe/'.$row->id ?>">Edit</a></td>
<td><a id="aDeleteOrderType" onclick="type_delete()" href="#.<?php echo $row->id ?>">Delete</a></td>
</tr>
<?php } ?>
</tbody>
Admin Footer
<script>
$("#aDeleteOrderType").click(function(e){
e.preventDefault();
$.ajax({
url: '<?php echo base_url().'admin/type_delete' ?>',
type: 'post',
data: {
},
success: function(msg)
{
if (msg == 'valid')
{
$.notify('Data Has Been Deleted', 'error')
}
}
});
});
</script>
Function di Controller
public function type_delete($id)
{
$is_logged_in1 = $this->session->userdata('is_logged_in');
$type = $this->session->userdata('type');
if(!isset($is_logged_in1) || $is_logged_in1 != true)
{
$data['error'] = '';
$this->load->view('login-1', $data);
}
else
{
$this->load->model('listtipeorder_model');
$this->listtipeorder_model->delete_list_type($id);
echo 'valid';
}
}
1 Jawaban:
cek
<pre> <a id="aDeleteOrderType" onclick="type_delete()" href="#.<?php echo $row->id ?>">Delete</a> </pre>
ganti jadi
<pre><a href="javascript:void(0);" data-id="<?php echo $row->id ?>" id="aDeleteOrderType">Delete</a></pre>
Admin Footer Benerin Jquery action nya, contoh buat ngambil data id nya
<pre>
<script type="text/javascript">
$(document).ready(function() {
$('#aDeleteOrderType').click(function() {
/* Act on the event */
var id = $(this).attr("data-id");
alert(id);
});
});
</script>
</pre>
kalo data id nya udah dapet tinggal kirim pake ajax ke action controllernya :) semoga membantu