Answer the question
In order to leave comments, you need to log in
How to correctly form layout for AJAX response in yii2?
In general, I do a little lazy filtering of laptops.
There are various checkboxes and sliders with prices in the aside. By clicking the Select button, Ajax is sent to the server and receives the necessary laptops.
But it's easier for me to form the layout on the server side.
It is necessary to form a layout where each laptop has something similar
<div class="col-md-4 col-xs-6">
<div class="product">
<div class="product-img">
<img src="./img/product01.png" alt="">
<div class="product-label">
<span class="sale">-30%</span>
<span class="new">NEW</span>
</div>
</div>
<div class="product-body">
<p class="product-category">Ноутбук</p>
<h3 class="product-name"><a href="product.html">product name goes here</a></h3>
<h4 class="product-price">$980.00 <del class="product-old-price">$990.00</del></h4>
<div class="product-rating">
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
</div>
</div>
<div class="add-to-cart">
<a href="product.html"><button class="add-to-cart-btn"><i class="fa fa-shopping-cart"></i> Посмотреть</button></a>
</div>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
Good morning.
In yii2 there is such method renderAjax() .
It returns a view in response to an ajax request. The first parameter accepts a file containing the layout you need, and the second can take a model with the necessary data.
return $this->renderAjax('path/to/file', ['model' => $model])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question