code:
public function actionTest() { Yii::$app->response->format = Response::FORMAT_JSON; return ['test' => 1]; }
Answer:
<?php{"test":1}
I do not understand why <\? php "adds the answer. I'm trying to use:
Yii::$app->response->format = Response::FORMAT_RAW;
and
return Json::encode(['test' => 1]);
but it didn’t help me
You should echoget the result. Here is the correct function:
echo
public function actionTest() { Yii::$app->response->format = Response::FORMAT_JSON;//optional echo Json::encode(['test' => 1]); return; }
Source: https://habr.com/ru/post/1606167/More articles:Pythonic way to add a list of vectors - pythonкак объединить карту и реплицировать по массиву целых чисел - listHow to output exec to a variable - phpHow to check if a specific function is called in Golang - goHow to exit a Kivy application using a button - pythonTrick to prevent the compiler from constantly expressing an expression - c ++Typhoon defaultAssembly () in Swift - dependency-injectionAre there any inverted operators for application? - haskellPolygon made of transparent pixels in pascal - pascal(Javascript) Explanation of "this" inside an array literal - javascriptAll Articles