mercredi 31 janvier 2018

cannot load jquery datatable from controller?

This is my laravel controller to return data in jason format.data returns perfectly.but cannot load the datatable with return value.please help. i am stuck here for 2 days.

    public function doctors_appointment(Request $request){
    $doctor_id=$request->input('doctorid');
    $serial_date=Carbon::today()->toDateTimeString();
    $query = DB::table('serial_in_queues')
        ->select([DB::raw('MAX(patient_serial_no) AS patient_serial_no'), 
    DB::raw('MAX(patient_serial_time) AS patient_serial_time')])
        ->where([['doctors_id', '=', $doctor_id],
               ['patient_serial_date','=','2018-01-25']])
             ->groupBy('doctors_id')->get()->first();$data=array(array('patient_serial_time'=>$query>patient_serial_time,'dt'=>0));return json_encode($data);
}

my Ajax:

        $(document).ready(function () {
        $('#autocomplete-custom-append').autocomplete({
            serviceUrl: '',
            onSelect: function (suggestions) {
                $('#doctors_id').val(suggestions.data);

                var doctor_id = suggestions.data;
                var table = $('#time-slot').DataTable({
                    retrieve: true,
                    paginate: false,
                    sort: false,
                    info: false,
                    filter: false,
                    serverSide: true,
                    ajax: {
                        type: 'GET',
                        url: 'doctorAppointment',
                        dataType: 'json',
                        data: {doctorid: doctor_id},
                        success:function (data) {
                            console.log(data);
                            alert(data[0].patient_serial_time);
                            columns:[
                                {"data":"data[0].patient_serial_time"}
                            ]
                        }
                    },
                })
             }
        })
    })



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire