Should be right but still "A system error has occurred"

Should be right but still "A system error has occurred"

saligiayyssaligiayys Posts: 12Questions: 7Answers: 0

Hi team,

The editor I am using is working all right.
I would like add to more fields from another MySQL table now.
So I need to use LeftJoin() and I need to use filed name like this 'table.field'
(I have not used LeftJoin yet, just before it change field to table.field)
After that, the DataTable is working all right, all data can be displayed, but when I click the update button in the Editor Form, there is a error "A system error has occurred (More information)."
But I have checked the Json, theyshould be all right~
Could you pleas help me take a look on my code~? Sorry for the inconvenience~Thank you very much!

        var editorMon = new $.fn.dataTable.Editor({
            ajax: {
                url: "inc/backend/editor_controllers/timesheetSummaryMon.php",
                dataType: 'json',
                type: 'POST',
                data: function (d) {
                    d.selectedUser = selectedUser;
                    d.weekStartDay = weekStartDay;
                    d.weekEndDay = weekEndDay;
                }
            },
            table: "#timesheet-summary-mon",
            fields: [{
                label: "Date:",
                name: "timesheet.date",
                type: 'datetime',
                def: function () { return new Date(); },
                displayFormat: 'D/M/YYYY',
                wireFormat: 'YYYY-MM-DD',
            }, 
            {
                label: "Job Number:",
                name: "timesheet.job_number",
                // type: "hidden"
            }, {
                label: "Job ID:",
                name: "timesheet.job_id",
                type: "hidden"
            }, {
                label: "Address:",
                name: "timesheet.address",
                // type: "hidden"
            }, 
            {
                label: "Start Time:",
                name: "timesheet.start_time"
            }, {
                label: "End Time:",
                name: "timesheet.end_time"
            },
            {
                label: "Hours:",
                name: "timesheet.hours",
                type: "hidden"
            }
            ],
        });


    //PHP
    Editor::inst($db, TBL_TIMESHEET)
        ->fields(
            Field::inst('timesheet.date'),
            Field::inst('timesheet.job_number'),
            Field::inst('timesheet.job_id'),
            Field::inst('timesheet.address'),
            Field::inst('timesheet.start_time'),
            Field::inst('timesheet.end_time')
                ->validator(function ($val, $data, $opts) {
                    if ($val <= $data['timesheet.start_time']) {
                        return "End time must be later than start time.";
                    }
                    return true;
                }),
            Field::inst('timesheet.hours')
                ->setFormatter(function ($val, $data, $opts) {
                    $startTime = strtotime($data['timesheet.start_time']);
                    $endTime = strtotime($data['timesheet.end_time']);
                    $timeDif = $endTime - $startTime;
                    $hours = $timeDif;
                    $hours = $hours / 60 / 60;
                    // return '123';
                    return $hours;
                })
        )
        ->where(function ($q) use ($selectedUser) {
            $q->where('timesheet.user_full_name', '(SELECT timesheet.user_full_name FROM ' . TBL_TIMESHEET . ' WHERE timesheet.id = ' . $selectedUser . ')', '=', false);
        })
        ->where('timesheet.date', $weekStartDay)
        ->debug(true)
        ->process($_POST)
        ->json();

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 57,300Questions: 1Answers: 9,127 Site admin
    Answer ✓

    Your code looks fine, but the error you are getting means that the server has returned invalid JSON. Perhaps you can give me a link to the page (PM it to me if you like) and I can debug it?

    You'd need to check the raw response from the server to the Ajax request that is resulting in this error.

    Allan

Sign In or Register to comment.