update codeigniter+ ajax

gini jadi saya punya problem, update ini id nya tidak terbaca.

dengan ajax.php

  var id;
    $(document).on("click", ".update-order", function() {
		var id = $(this).attr("data-id");

		$.ajax({
			method: "POST",
			url: "<?php echo base_url('order/update'); ?>",
			data: "id=" +id
		})
		.done(function(data) {
			$('#tempat-modal').html(data);
			$('#update-order').modal('show');
		})
	})

    $(document).on('submit', '#form-update-order', function(e){
		var data = $(this).serialize();

		$.ajax({
			method: 'POST',
			url: '<?php echo base_url('stock/prosesUpdate'); ?>',
			data: data
		})
		.done(function(data) {
			var out = jQuery.parseJSON(data);

			tampilOrder();
			if (out.status == 'form') {
				$('.form-msg').html(out.msg);
				effect_msg_form();
			} else {
				document.getElementById("form-update-order").reset();
				$('#update-order').modal('hide');
				$('.msg').html(out.msg);
				effect_msg();
			}
		})

controller Order.php

   public function update($id) {

        $listOrderUser = $this->mOrder->listOrderUser();
        $listOrder     = $this->mOrder->listOrderDetail($id);

		$data = array(
            'listOrder'     => $listOrder,
            'listOrderUser' => $listOrderUser,
            'username'      => $this->session->userdata('username')
        );

		echo show_my_modal('modals/modal_order_edit', 'update-order', $data);
	}

	public function prosesUpdate() {

        $this->form_validation->set_rules('qty', 'QTY', 'trim|required');
        $this->form_validation->set_rules('keterangan', 'keterangan', 'trim|required');

		$data 	= $this->input->post();
		if ($this->form_validation->run() == TRUE) {
			$result = $this->mOrder->editOrder($data);

			if ($result > 0) {
				$out['status'] = '';
				$out['msg'] = show_succ_msg('Data Kota Berhasil diupdate', '20px');
			} else {
				$out['status'] = '';
				$out['msg'] = show_succ_msg('Data Kota Gagal diupdate', '20px');
			}
		} else {
			$out['status'] = 'form';
			$out['msg'] = show_err_msg(validation_errors());
		}

		echo json_encode($out);
	}

dan model

  // Listing Berdasarkan username
        public function listOrderUser() {
            $user= $this->session->userdata('username');
            $this->db->select('*');
            $this->db->from('order');
            $this->db->where(array('username' => $user));
            $query = $this->db->get();
            return $query->result_array();
        }

        // Listing Berdasarkan id
        public function listOrderDetail($id) {
            $this->db->select('*');
            $this->db->from('order');
            $this->db->where('id',$id);
            $this->db->order_by('id','DESC');
            $query = $this->db->get();
            return $query->result_array();
        }

        // Edit Order
        public function editOrder($data) {
            $this->db->where('id',$data['id']);
            $this->db->update('order',$data);
        }

mohon bantuannya, terima kasih :)

avatar umaroliver7
@umaroliver7

17 Kontribusi 1 Poin

Diperbarui 6 tahun yang lalu

2 Jawaban:

errornya gimana ? banyak kasus id tidak terbaca. di Javascript kah atau di back end?

avatar arhen03
@arhen03

55 Kontribusi 23 Poin

Dipost 6 tahun yang lalu

key nya di <pre> var id = $(this).attr("data-id"); </pre> apakah attribut data-id sudah mengandung id data yang akan di update ?

avatar AsrulMaa
@AsrulMaa

23 Kontribusi 1 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban