L
L
Leopandro2016-02-26 12:21:45
Yii
Leopandro, 2016-02-26 12:21:45

How to PJAX update another part of the page?

Main.php file:

<div class="wrap">
    <? \yii\widgets\Pjax::begin()?>
    <?php
    NavBar::begin([
        'brandLabel' => 'Название компании',
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
            'id' => 'ww',
            'class' => 'navbar-inverse navbar-relative',
        ],
    ]);

    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right', 'id' => 'ww'],
        'items' => User::getMenuItemsByRoleUser(!Yii::$app->user->isGuest ? Yii::$app->user : false,Yii::$app->user->isGuest)
    ]);
    NavBar::end();
    ?>
    <? \yii\widgets\Pjax::end()?>
    <div class="container" id="content_inner">
        <? \yii\widgets\Pjax::begin(['timeout' => '3000'])?>
        <?= Breadcrumbs::widget([
            'homeLink'=>[
                'label' => 'Главная',  // required
                'url' =>  \yii\helpers\Url::home(),      // optional, will be processed by Url::to()
            ],
            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
        ]) ?>

        <?= $content ?>
        <? \yii\widgets\Pjax::end()?>
    </div>
</div>

When I click on the NavBar link, Ajax returns the content that needs to be placed in how to do this? Or is it better for me to return the whole page (then how to do it)?
This is what it looks like visually:
cdcbdb68a71e469482a70034857b561a.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
matperez, 2016-02-26
@matperez

You can try this
https://github.com/defunkt/jquery-pjax#pjax
The container in which you have the content needs to be given an id, for example #content-pjax-container. And then call something like this in the click handler on the link..

var url = $(this).attr('href');
$.pjax({url: url, container: '#content-pjax-container'})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question