Answer the question
In order to leave comments, you need to log in
How to get article content via AJAX?
Hello! Articles are displayed cyclically on the site, you need to create an AJAX request that would display more detailed content in popUp. Please help me figure this out. How to create a request in general and display it back? In the current state, I receive an object - how to parse it, if this is correct at all?
$.ajax({
url: '/category/data',
data: {productId:productId},
type: 'GET',
success: function(res){
alert(res)
},
error: function(){
alert('Error!');
}
});
public function actionData($productId){
if (Yii::$app->request->isAjax) {
$res = Product::find()->where(['id'=> $productId])->one();
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ['res'=> $res];
}
}
Answer the question
In order to leave comments, you need to log in
Just replace
success: function(res){
alert(res)
},
success: function(res){
console.log(res)
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question