Published December 26, 2024 by RIT with 0 comment

CARA OPER NILAI PADA AJAX MENGGUNAKAN FUNCTION



Hello I have problem return a value in function using ajax, And I am solved problem after search in google.com and recomend from stackoverflow. So, in my case only add async : false in function ajax.
function insert(data_nya){
    let returnStatus = false;
    $.ajax({
        method: 'POST',
        url: "<?= base_url(); your_controller ?>",
        data: data_nya,
        async: false, // add async for return value variable returnStatus.
        success: function(res){

            let data_nya  = $.parseJSON(res);
            if(data_nya.status_insert == 2){
                
                returnStatus = true;

            }else{

                returnStatus;
            }
        }
    }); // end ~ ajax
    return returnStatus;
} // end ~ function


Enjoy it. ^_^

TAG TAGS :
return value ajax || How to return value ajax from function || ajax || how to return value from function ajax || jquery || ajax langsungkoding.blogspot.com | langsungkoding |

REFERENCE :
Read More
      edit
Published October 02, 2024 by RIT with 0 comment

cara mengatasi ONLY_FULL_GROUP_BY pada codeigniter 3



Assalamualaikum warohmatullohi wabarokatuh,
Wa alaikum salam warohmatullohi wabarokatuh,

Cara mengatasi SELECT list is not in GROUP BY clause and contains nonaggregated column 'your_db' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by. Pada codeigniter, menurut saya ini terjadi karena beda versi, dan kita harus merubah pengaturan melalui myql nya langsung referensi nya bisa dilihat disini. atau jika anda tidak bisa melakukan perubahan karena tidak bisa akses, anda bisa sisipkan kode berikut kedalam query jika menggunakan php native. Jika menggunakan framework, sisipkan kode ini kedalam model atau kedalam construct controllernya, berikut kode nya :

kode dasar :
$this->db->query('SET SESSION sql_mode = ""');

// ONLY_FULL_GROUP_BY
$this->db->query('SET SESSION sql_mode =
                  REPLACE(REPLACE(REPLACE(
                  @@sql_mode,
                  "ONLY_FULL_GROUP_BY,", ""),
                  ",ONLY_FULL_GROUP_BY", ""),
                  "ONLY_FULL_GROUP_BY", "")');

jika kalian menempatkan kode nya di controller :
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class YourController extends CI_Controller {

	public function __construct()
	{
		parent::__construct();

		$this->db->query('SET SESSION sql_mode = ""');

		// ONLY_FULL_GROUP_BY
		$this->db->query('SET SESSION sql_mode =
		                  REPLACE(REPLACE(REPLACE(
		                  @@sql_mode,
		                  "ONLY_FULL_GROUP_BY,", ""),
		                  ",ONLY_FULL_GROUP_BY", ""),
		                  "ONLY_FULL_GROUP_BY", "")');
	}

Demikian cara disable ONLY_FULL_GROUP_BY pada codeigniter, jika ada kesulitan mengenai artikel ini, bisa tinggalkan komentar dibawah ini. Terima Kasih

TAG TAGS :
CARA disable ONLY_FULL_GROUP_BY PADA CODEIGNITER | CARA disable ONLY_FULL_GROUP_BY PADA CODEIGNITER | CARA disable ONLY_FULL_GROUP_BY MENGGUNAKAN CODEIGNITER | HOW TO disable ONLY_FULL_GROUP_BY USE CODEIGNITER | HOW TO disable ONLY_FULL_GROUP_BY WITH CODEIGNITER | disable ONLY_FULL_GROUP_BY in CODEIGNITER | disable ONLY_FULL_GROUP_BY on CODEIGNITER langsungkoding.blogspot.com | langsungkoding |


BACA JUGA :
Read More
      edit
Published June 25, 2024 by RIT with 0 comment

CHECKBOX IN PAGINATED DATATABLES



Hello I have problem checkbox in paginated, so I am trying choice and check data in datatables and parse value in input hidden, but in second page choice and check not working. And below this my code for solved problem checkbox in second pagination.
let your_date = your_date;

$(".div_for_dataTables").empty();
$(".id_login").val("");

$.ajax({

    method: "POST",
    url: url_nya+'folder_controller/Contoller/getData',
    data: {date_to_controller : your_date},
    success: function(res) {

        let data_nya  = $.parseJSON(res);
        alert('Data exists', 'success');
         // START TABLE
            let html_code = `<table class="table table-bordered _dataTables">`;
                html_code += `
                            <thead>
                                <tr>
                                <td>No. </td>
                                <td>Name</td>
                                <td>Option</td>
                                </tr>
                            </thead>
                            <tbody>
                            `;

            for (let i = 0; i < data_nya.length; i++) {
                // Add dataTables in here
                html_code += `
                    <tr >
                        <td>`+parseInt(1+i)+`</td>
                        <td>`+data_nya[i].name_+`</td>
                                                        <td>
                            <div class="form-check">
                            <input class="form-check-input choice_check" type="checkbox" id_login="`+data_nya[i].id_login+`" name_xxx="`+data_nya[i].name_+`" value="">
                            </div>
                        </td>
                    </tr>
                    `;

            } // END FOR
            html_code += `</tbody>`
            html_code += `</table>`;

            $(".div_for_dataTables").append(html_code);

            let tables_ = $('._dataTables').DataTable({
                                     "iDisplayLength": 5,
                                     "lengthMenu": [[5, 10, -1], [5, 10, "All"]]
                                });
            let rows = tables_.rows({ 'search': 'applied' }).nodes();

         // END TABLE

            let array_push = [];
            let array_push_id = [];
            
            $('.choice_check', rows).change(function() {

                let name   = $(this).attr('name_xxx');
                let id_login = $(this).attr('id_login');

                if($(this).is(":checked")) {
                    
                    array_push.push(" [ "+name+" ] ");
                    array_push_id.push(id_login);

                }else{

                    let index_name = array_push.indexOf(" [ "+name+" ] ");
                    let index_id_login = array_push_id.indexOf(id_login);

                    if (index > -1) {

                        array_push.splice(index_name, 1);
                        array_push_id.splice(index_id_login, 1);
                    }
                }

                $(".name_div").text(array_push);
                $("[name='id_login']").val(array_push_id);

            });
    } // END SUCCESS
                
}); // END AJAX 


And in your case, added this below code :
let tables_ = $('._dataTables').DataTable({
                 "iDisplayLength": 5,
                 "lengthMenu": [[5, 10, -1], [5, 10, "All"]]
            });

let rows = tables_.rows({ 'search': 'applied' }).nodes();


And added code rows this code on your function click checkbox :
  $('.choice_check', rows).change(function() {


Enjoy it. ^_^

TAG TAGS :
checkbox in paginated datatable || How to catch values of checkboxes that are paginated with DataTables plugin || checkbox || how to use checkbox in second pagination || DataTables langsungkoding.blogspot.com | langsungkoding |

REFERENCE :
Read More
      edit
Published August 11, 2023 by RIT with 0 comment

CARA MENGGUNAKAN TRANS_START PADA CODEIGNITER



Assalamualaikum warohmatullohi wabarokatuh,
Wa alaikum salam warohmatullohi wabarokatuh,

Trans_start atau transaction pada codeigniter berfungsi untuk menghentikan query. Pada kasus ini, ada 2 query insert, saat menjalankan query, dengan sengaja melakukan kesalahan di salah satu query nya. Yang di ingin kan adalah jika salah satu query salah maka jangan eksekusi semua query. Langsung saja pada script.

<?php


function add_data($datas, $data_nis)
{

    // trans_start untuk cek apakah query dari controller atau model ada masalah
	$this->db->trans_start(); # Starting Transaction

	$this->db->trans_strict(FALSE); # See Note 01. If you wish can remove as well 

	$this->db->insert_batch("tb_siswa2", $datas);

	$this->db->insert_batch("tb_siswa_sekolah", $data_nis);

	$this->db->trans_complete(); # Completing transaction


	if ($this->db->trans_status() === FALSE) {
	    
	    # Something went wrong.
	    $this->db->trans_rollback();
	    
	    return FALSE;
	} 
	else {
	    
	    
	    # Everything is Perfect. 
	    # Committing data to the database.
	    $this->db->trans_commit();
	    
	    return TRUE;
	}

}

Pada script diatas adalah kode yang benar dan jika di jalankan akan return true, dan akan di input ke database,
untuk percobaan salah nya silahkan ubah pada kode

$this->db->insert_batch("tb_siswa_sekolah", $data_nis);
ubah menjadi
$this->db->insert_batch("tb_siswa_sekolah", $data_nis2);
maka aka terdapat error dan query / function nya tidak akan di jalankan.

Demikian cara start_transaction pada codeigniter, jika ada kesulitan mengenai artikel ini, bisa tinggalkan komentar dibawah ini. Terima Kasih

TAG TAGS :
CARA START_TRANS PADA CODEIGNITER | CARA TRANSACTION PADA CODEIGNITER | CARA TRANSACTION MENGGUNAKAN CODEIGNITER | HOW TO TRANS_START USE CODEIGNITER | HOW TO TRANS_START WITH CODEIGNITER | TRANS_START in CODEIGNITER | TRANS_START on CODEIGNITER langsungkoding.blogspot.com | langsungkoding |


BACA JUGA :
Read More
      edit