Render Layout Menu Using Pjax in Yii2

i tried to implement notification in menu bar like facebook in yii2. basically, i use Pjax to retrieve the data when the dropdown is opened.


function getNotification(){

    //the resason of length 0 instead of 1 because this code is executed first then the notifcation is opened

    if($('#notif-expansion').parent().find('.open').length == 0){

       $("#notification-form").submit();

    }

}

the menu notification is in the menu bar / layout/main.php the code looks like this.


    echo Html::beginForm(['../../notification/index'], 'post', ['id' => 'notification-form', 'data-pjax' => '', 'class' => 'form-inline']);


    echo "

        <ul class='navbar-nav navbar-right nav'>

            <!-- id notif-expansion is used in js to check whether the dropdown is opened or closed-->

            <li id='notif-expansion' class='dropdown dropdown-large'>

                <a class='dropdown-toggle' onclick='getNotification()' data-toggle='dropdown'>

                    <span class='glyphicon glyphicon-alert'>

                    </span>

                    <b class='caret'></b>

                </a>

                <ul  class='dropdown-menu dropdown-menu-large row'>

                    <div class='col-md-12'>

                        <label><div style='width:400px' align='center'> Notifications </div></label>

                        <hr>";


                        if(isset($recent_notifications_provider)){

                            echo $this->render('_notifications', ['recent_notifications_provider' => $recent_notifications_provider]);

                        }

                        else{

                            echo Spinner::widget(['preset' => 'medium', 'align' => 'center', 'color' => 'blue']);


                        }


    echo  "        </div>

                </ul>

            </li>

        </ul>

     ";


    echo  Html::endForm();

So when the menu is clicked the getNotification function is triggered then the form is submitted and execute the function below




   public function actionIndex(){

        $this->renderAjax('../../layout/main', ['recentnotificationprovider' , $recentnotificationprovider);

    }

i just confuse where to render it since i donot know the current page.

Anyone has got solution for this? (I am opened to other solutions)