D
D
Dmitry2020-09-23 14:40:46
Yii
Dmitry, 2020-09-23 14:40:46

Why is the Kartik GridView SyntaxError thrown?

I installed the Kartik GridView extensions, set up an edittable , I try to change the article in the column, I get the error "SyntaxError: Unexpected token < in JSON at position 35", how can I fix it already broke my head =(
But the data itself is saved in the database after refreshing the page!

:

[
                'attribute' => 'article',
                'class' => 'kartik\grid\EditableColumn',
                'editableOptions'=> function ($model, $key, $index) {
                    return [
                        'header'=>'Name',
                        'size'=>'md',
                        'formOptions' => ['action' => '/backend/product/product/demoe'],
                        'inputType'=>\kartik\editable\Editable::INPUT_TEXT,
                    ];
                },
            ],


My Controller with action:
public function actionDemoe()
    {
        if (Yii::$app->request->post('hasEditable')) {
            $bookId = Yii::$app->request->post('editableKey');
            $model = Products::findOne($bookId);
            $out = Json::encode(['output'=>'', 'message'=>'']);
            $posted = current($_POST['Products']);
            $post = ['Products' => $posted];
            if ($model->load($post)) {
                $model->save();
                $output = '';
                if (isset($posted['article'])) {
                    $output = Yii::$app->formatter->asDecimal($model->article, 2);
                }
                $out = Json::encode(['output'=>$output, 'message'=>'']);
            }
            echo $out;
            return;
        }
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question