Когда я пытаюсь использовать React, оператор выборки не возвращает никаких данных. Любая помощь по этому поводу будет признательна, так как я потратил пару времени, пытаясь выяснить эту ошибку.
Вот моя функция выборки компонента ReactJs
Код: Выделить всё
fetchPoll(){
console.log("before json")
fetch(URL_HOME, { method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(json => {
console.log("before json2")
this.setState({pollTrendings:json})
console.log("before json3")
console.log(this.pollTrendings)
})
console.log("endingjson")
}
Ниже приведена конечная точка моего API
Код: Выделить всё
public static function allowedDomains()
{
return [
'*',
];
}
public function behaviors()
{
return array_merge(parent::behaviors(), [
// For cross-domain AJAX request
'corsFilter' => [
'class' => \yii\filters\Cors::className(),
'cors' => [
// restrict access to domains:
'Origin' => static::allowedDomains(),
'Access-Control-Request-Method' => ['POST'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 3600, // Cache (seconds)
],
],
]);
}
public function actionTrendingmusic(){
//find all the rows in the trending table with status current and type music
$trending = Trending::find()
->where(['status'=>'current', 'type'=>'music'])
->all();
return $trending;
Подробнее здесь: https://stackoverflow.com/questions/523 ... m-yii2-api
Мобильная версия