Postingan lainnya
[SOLVED] Ajax di codeigniter
$(document).ready(function(){
$.ajaxSetup({
type:"POST",
url: "https://localhost/order/get_produk",
cache: false,
});
$("#cat").bind('change', function(){
var idCat = $(this).val();
if(idCat > 0){
$.ajax({
data:{cat:'produk',id:idCat},
success: function(response){
$("#produk").html(response);
},
error: function(response){
$('#produk').html('<option>kosong</option>');
}
})
}
});
Saya nyoba ngirim data pakai ajax, tapi ada error di console chrome :
Failed to load resource: the server responded with a status of https://localhost/order/get_produk 403()
0
2 Jawaban:
Jawaban Terpilih
perbaikan di jquery <pre> $(document).ready(function(){ var csrfName = '<?php echo $this->security->get_csrf_token_name(); ?>', csrfHash = '<?php echo $this->security->get_csrf_hash(); ?>'; $.ajaxSetup({ type:"POST", url: "https://localhost/order/get_produk", cache: false, });
$("#cat").bind('change', function(){
var idCat = $(this).val();
if(idCat &gt; 0){
$.ajax({
data:{csrfName:csrfHash,cat:'produk',id:idCat},
success: function(response){
$("#produk").html(response);
},
error: function(response){
$('#produk').html('&lt;option&gt;kosong&lt;/option&gt;');
}
})
}
});
</pre>
1