Cara memunculkan data status dengan ajax

Saya ingin menampilkan status tetapi hasilnya undefined kenapa ya ?

ajax

<script>
$(document).ready(function (e) {
    var table = $("#table1_test").DataTable();
        $('#previewButton').on('click', function () {
        var tglawal = $('#tglawal_pre').val();
        var tglakhir = $('#tglakhir_pre').val();
        // dateControl.value = '2017-06-01';
        let url = "{{ route('previewPertanggal', ['tglawal' => ':post_id', 'tglakhir' => ':vote']) }}";
        url = url.replace(':post_id', tglawal);
        url = url.replace(':vote',tglakhir);
        $.ajax({
            type: 'GET',
            url: url,
            success: function (data) {
                // console.log(data);
                // Update the table with the new data
                        table.destroy();
                        $('.refresh').remove();
                        for (let index = 0; index < data['success'].length; index++) {
                            // const element = data[index];
                            var nomor = index + 1
                    var foto_aset = '<td><img id="foto_aset" src="' + data['success'][index]['foto_aset'] + '"  width="40" height="40"></td>';

                    $('#isi_data').append('<tr class="refresh"><td>' +
                        nomor + '</td><td>' + data['success'][index]['kode_aset'] +
                        '</td><td>' +
                        data['success'][index]['satuan']['nama_satuan'] + '</td><td>' +
                        data['success'][index]['desc_pelepasanstatus']+ '</td><td>' +
                        data['success'][index]['tgl_beli'] + '</td><td>' +
                        data['success'][index]['tgl_pakai'] + '</td><td>' +
                        data['success'][index]['harga_perolehan'] + '</td><td>' +
                        data['success'][index]['metode'] + '</td><td>' +
                        data['success'][index]['umur'] + '</td><td>' +
                        data['success'][index]['supplier']['nama_supplier'] + '</td><td>' +
                        data['success'][index]['keterangan'] + '</td><td>' +
                        data['success'][index]['no_faktur'] + '</td><td>' +
                        data['success'][index]['nama_aset'] + '</td><td>' +
                        // data['success'][index]['jabatan']['desc_jabatan'] + '</td><td>' +
                        data['success'][index]['departement']['nama_departement'] + '</td><td>' +
                        data['success'][index]['lokasi'] + '</td><td>' +
                        foto_aset + '</td><td>' +
                        data['success'][index]['persentase'] + '</td><td>' +
                        data['success'][index]['tarif'] + '</td></tr>');

                        }
                        table = $("#table1_test").DataTable();
                        // $('#quoteFormPreview').modal().hide();
                        // $("#quoteFormPreview .close").click()
            },
            error: function (xhr, status, error) {
                // Handle the error
                console.log(error);
            }
        });
    });

});
</script>

controller

public function previewPertanggal($tglawal, $tglakhir)
    {
        // dd("sadasdadadada");
        // dd($tglawal);
        $pelepasan = DB::table('pelepasanstatus_asset')->where('desc_pelepasanstatus')->get();
        $satuan = DB::table('satuan')->where('status_satuan','=','1')->get();
        $supplier = DB::table('supplier')->where('status_supplier','=','1')->get();
        $groupasset = DB::table('group_asset')->where('status_grup_asset','=','1')->get();
        $datakaryawan = DB::table('data_karyawan')->where('status_data_karyawan','=','1')->get();
        $departement = DB::table('departement')->where('status','=','1')->get();
        $listasset = DB::table('list_asset')->where('id_pelepasanstatus','=','1')->get();
        $listasset = DB::table('list_asset')
        ->leftjoin('pelepasanstatus_asset', 'list_asset.id_pelepasanstatus', '=', 'pelepasanstatus_asset.id_pelepasanstatus')
        ->leftjoin('satuan', 'list_asset.id_satuan', '=', 'satuan.id_satuan')
        ->leftjoin('supplier', 'list_asset.id_supplier', '=', 'supplier.id_supplier')
        ->leftjoin('group_asset', 'list_asset.id_grup', '=', 'group_asset.id_grup')
        ->leftjoin('data_karyawan', 'list_asset.id_karyawan', '=', 'data_karyawan.id_karyawan')
        ->leftjoin('departement', 'list_asset.id_departement', '=', 'departement.id_departement')
        ->leftjoin('jabatan', 'data_karyawan.id_jabatan', '=', 'jabatan.id_jabatan')
        ->whereBetween('list_asset.created_at',[$tglawal, $tglakhir])
        ->select('list_asset.*', 'satuan.nama_satuan', 'supplier.nama_supplier', 'group_asset.nama_grup_aset', 'jabatan.desc_jabatan', 'departement.nama_departement', 'data_karyawan.nama_karyawan','pelepasanstatus_asset.desc_pelepasanstatus')
        ->get();
        $previewtanggal =  listAsset::with('satuan', 'supplier', 'departement', 'Pelepasan')->whereBetween('list_asset.created_at', [$tglawal, $tglakhir])->get();
        return response()->json(['success'=>$previewtanggal, 'status' => 1]);


}

di databasenya table list_asset bagian id_penghaspusan status relasi dengan tabel pelepasanstatus_asset bagian id_penghapusan nah saya ingin mengambil bagian desc_penghapusan tetapi yang keluar undefined, dan jika memakai kode seperti

     data['success'][index]['pelepasanstatus_asset']['desc_pelepasanstatus']+ '</td><td>' +

maka akan error error uncaught typeerror: cannot read properties of undefined (reading 'desc_pelepasanstatus') at object.success (reportdaftarasset:408:75) at i (jquery.min.js:2:28017) at object.firewith [as resolvewith] (jquery.min.js:2:28783) at a (jquery.min.js:4:14035) at xmlhttprequest.<anonymous> (jquery.min.js:4:16323) success @ reportdaftarasset:408 i @ jquery.min.js:2 firewith @ jquery.min.js:2 a @ jquery.min.js:4 (anonymous) @ jquery.min.js:4 load (async) send @ jquery.min.js:4 ajax @ jquery.min.js:4 (anonymous) @ reportdaftarasset:397 dispatch @ jquery.min.js:3 q.handle @ jquery.min.js:3

ini gambar table database pelepasanstatus_asset

image.png

gambar database tabel list_asset

image.png

Mohon bantuannya makasih....

avatar zkdlinnn
@zkdlinnn

10 Kontribusi 2 Poin

Dipost 1 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban