Postingan lainnya
Buku Ini Koding!
Baru!
Buku ini akan jadi teman perjalanan kamu belajar sampai dapat kerjaan di dunia programming!
Ajax tidak jalan data tidak masuk
mohon bantuanya ini ajaxnya gak jalan udah saya kasih cdn, tapi yg bener di atas atau dibawah y ? dan request tidak jalan, alias cuman redirect doang. mohon bantuanya
script lengkapnya :
View produk
<form class="input-data" method="POST">
<div class="row">
<div class="col-md-6">
<div class="form-group" style="margin-top:10px; text-align: center!important;">
<label class="form-control-label">Ukuran</label>
<?php
$options = array('xl'=> 'XL','m' => 'M','s' => 'S');
$att = array('class' => 'form-control');
echo form_dropdown('ukuran', $options, 'XL', $att);
?>
</div>
</div>
<div class="col-md-6">
<div class="form-group" style="margin-top:10px; text-align: center!important;">
<label class="form-control-label">Jumlah</label>
<input id="qty" type="number" name="qty" class="form-control" required>
</div>
</div>
</div>
<div class="form-group">
<?php
$cd = $produk->code_products;
$name = $produk->title_products;
$picture = $produk->gambar;
$price = $produk->price_products;
$crsf = $this->security->get_csrf_hash();
echo form_hidden('cd', $cd);
echo form_hidden('titel', $name);
echo form_hidden('img', $picture);
echo form_hidden('prc', $price);
echo form_hidden('csrf_wrr_token',$crsf);
?>
</div>
<button type="submit" name="add-data" class="btn btn-light" style="margin-top: -15px; margin-bottom: -20px;color: #5b6366"> Add To Cart</button>
</form>
<!-- <p><tt id="results"></tt></p> -->
<script>
$(document).ready(function(){
$('button[name=add-data]').click(function(e){
e.preventDefault();
var data = $('.input-data').serialize();
$.ajax({
type: 'POST',
url: "<?php base_url('cart/add');?>",
data: data,
success: swal 'Submited!', 'Berhasil Menambah ke Keranjang','success',
button: "OK!"
});
});
});
// function showValues() {
// var str = $( ".input-data" ).serialize();
// $( "#results" ).text( str );
// }
// $( "input[type='checkbox'], input[type='radio']" ).on( "click", showValues );
// $( "select" ).on( "change", showValues );
// showValues();
</script>
Function add
function add(){
// print_r($this->input->post('qty'));
$data = array(
'id' => $this->input->post('cd'),
'qty' => $this->input->post('qty'),
'price' => $this->input->post('prc'),
'name' => $this->input->post('titel'),
'ukuran' => $this->input->post('ukuran'),
'gambar' => $this->input->post('img'),
);
// print_r($data);
$this->cart->insert($data);
}
dan swal tidak muncul
4 Jawaban:
function add(){
// print_r($this->input->post('qty'));
$data = array(
'id' => $this->input->post('cd'),
'qty' => $this->input->post('qty'),
'price' => $this->input->post('prc'),
'name' => $this->input->post('titel'),
'ukuran' => $this->input->post('ukuran'),
'gambar' => $this->input->post('img')
);
// print_r($data);
$this->cart->insert($data);
}
Jawaban Terpilih
ngaruh y emang bang ? sama aja gak bisa
<pre> function add(){
// print_r($this->input->post('qty'));
$data = array();
$data = array(
'id' => $this->input->post('cd'), 'qty' => $this->input->post('qty'), 'price' => $this->input->post('prc'), 'name' => $this->input->post('titel'), 'ukuran' => $this->input->post('ukuran'), 'gambar' => $this->input->post('img') );
// print_r($data);
$this->cart->insert($data);
} </pre>