Yii2 Pjax Tutorial
What is AJAX?
AJAX = Asynchronous JavaScript and XML.
AJAX is a technique for creating fast and dynamic web pages.
AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
Classic web pages, (which do not use AJAX) must reload the entire page if the content should change.
Examples of applications using AJAX: Google Maps, Gmail, YouTube, and Facebook.
YII2 PJAX
pjax is a jQuery plugin that allows quick website navigation by combining ajax and pushState. It works by sending a special request to the server every time a link is clicked or a form is submitted. The server sends back the content that needs to be updated, pjax replaces old content with new content and pushes the new URL to browser history, without the need to update the whole page.
Regular requests download the whole page. Pjax can ask the server to send only the required part of the content.
Steps using pjax in yii2 framework
1 Add one line in the beginning of your view.
<?php
use yii\widgets\Pjax;
?>
2 Add two lines around the content that needs partial updating.
<?php Pjax::begin(); ?>
Content that needs to be updated
<?php Pjax::end(); ?>
Ajax Search With the GridView
Getting Values From a Table Using Ajax
Submitting Forms Using Ajax
efrf
ReplyDelete