Answer the question
In order to leave comments, you need to log in
How to display a piece of content using Pjax yii2?
Good afternoon, question.
There is a site bar. It has categories and a search form. Search form - select2 is already screwed and working when entering into the form, it produces results from the database.
The question is how to implement such a thing, I can not understand. When entering data into the search string, in the right column, the result was displayed in the left column.
screen for understanding
I looked at pjax examples, here https://nix-tips.ru/yii2-vnikaem-v-pjax.html
But I didn’t figure out where and how to wrap the widget for it to work
, in fact, send data from one form , get dynamic into another...
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Do you have a drop down list?
<select name="spjax" id="spjax">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<?php
Pjax::begin([
'id' => 'view-mode-pjax'
])
?>
<div class="col-lg-4">
<h2>Heading <?= $Ipjax ?></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur.</p>
<p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation »</a></p>
</div>
<?php
Pjax::end();
$this->registerJs("
$(function(){
$('#spjax').on('change', function(){
var Id = $(this).val()
console.log(Id)
$.pjax.reload({
container: \"#view-mode-pjax\", // контейнер, в котором надо обновить данные.
url: window.location.href,
timeout: 0,
data: {
'id': Id // данные, которые отправляются на сервер.
},
});
})
})
", View::POS_END)
?>
public function actionIndex()
{
$Ipjax = Yii::$app->request->get('id') ?: null;
return $this->render('index', ['Ipjax' => $Ipjax]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question