How to update part of the content in Yii2 using JavaScripit and Pjax

How to update part of the content in Yii2 using JavaScripit and Pjax

The first thing we need to do is include "Pjax" itself:

use yiiwidgetsPjax;

Next, wrap the desired content in the Pjax widget. For example:

<?php Pjax::begin([ 'id' => 'pjaxContent'
]); ?>

Content here

<?php Pjax::end(); ?>

And to forcefully reload the desired content, run the following JavaScript code:

$.pjax.reload({container: '#pjaxContent'});

Don’t forget that the jQuery framework must be included (in Yii, it comes by default).

Or bind the reload to an event:

$(document).on('click', '#myBtn', function (e) {
	e.preventDefault();

	$.pjax.reload({container: '#pjaxContent'});

	return false;
});
Posts on similar topics

Are you having problems with your Yii2 framework website? Do you need additional functionality?
>Then write to me via the feedback form, and I will try to help you.

Write a comment

Your email address will not be published. Required fields are marked *