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

avatar maszgalang
@maszgalang

297 Kontribusi 80 Poin

Diperbarui 5 tahun yang lalu

4 Jawaban:

function add(){

// print_r($this->input->post('qty'));

$data = array(

&#039;id&#039; =&gt; $this-&gt;input-&gt;post(&#039;cd&#039;),
&#039;qty&#039; =&gt; $this-&gt;input-&gt;post(&#039;qty&#039;),
&#039;price&#039; =&gt; $this-&gt;input-&gt;post(&#039;prc&#039;),
&#039;name&#039; =&gt; $this-&gt;input-&gt;post(&#039;titel&#039;),
&#039;ukuran&#039; =&gt; $this-&gt;input-&gt;post(&#039;ukuran&#039;),
&#039;gambar&#039; =&gt; $this-&gt;input-&gt;post(&#039;img&#039;)

);

// print_r($data);

$this->cart->insert($data);

}

avatar sanlie
@sanlie

22 Kontribusi 2 Poin

Dipost 5 tahun yang lalu

Jawaban Terpilih

ngaruh y emang bang ? sama aja gak bisa

avatar maszgalang
@maszgalang

297 Kontribusi 80 Poin

Dipost 5 tahun yang lalu

<pre> function add(){

// print_r($this-&gt;input-&gt;post('qty'));

$data = array();

$data = array(

'id' =&gt; $this-&gt;input-&gt;post('cd'), 'qty' =&gt; $this-&gt;input-&gt;post('qty'), 'price' =&gt; $this-&gt;input-&gt;post('prc'), 'name' =&gt; $this-&gt;input-&gt;post('titel'), 'ukuran' =&gt; $this-&gt;input-&gt;post('ukuran'), 'gambar' =&gt; $this-&gt;input-&gt;post('img') );

// print_r($data);

$this-&gt;cart-&gt;insert($data);

} </pre>

avatar sanlie
@sanlie

22 Kontribusi 2 Poin

Dipost 5 tahun yang lalu

gak ngaruh

avatar maszgalang
@maszgalang

297 Kontribusi 80 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban