Answer the question
In order to leave comments, you need to log in
Why does yii2 sometimes return non-json format in ajax request?
When getting return result of ajax request
$response = [..];
Yii::$app->response->format = Response::FORMAT_JSON;
return $response;
<![CDATA[YII-BLOCK-HEAD]]><![CDATA[YII-BLOCK-BODY-BEGIN]]>
then json The data Answer the question
In order to leave comments, you need to log in
This indicates that $response is not what is expected, and the application returns some kind of exception. Moreover, he is trying to give a template that is made a little against the rules. Most likely in /views/layouts/main.php the template is made without $this->beginPage(), $this->beginBody(), and the like.
I recommend using a controller inherited from \yii\rest\Controller for Ajax data, and not from \yii\web\Controller.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question