2017-03-16 20 views
0
  • Pjax警報

還有就是alert.php包括在上述$內容佈局文件。這是如下:使用祝酒pjax沒有完全刷新

<?php Pjax::begin(['id'=> 'new-alert','enablePushState' => false]); ?> 
     <?= \odaialali\yii2toastr\ToastrFlash::widget([ 
       'options' => [ 
        'positionClass' => 'toast-bottom-full-width', 
        //'progressBar' => true, 
        'timeOut' => 6000, 
        'extendedTimeOut' => 2000      
       ] 
     ]);?> 
<?php Pjax::end(); ?> 

並獲得在阿賈克斯的提示信息,有以下容器

$.pjax.reload({container:'#new-alert'}); 

這導致警報消息顯示通話,但也發送一個Ajax請求的URL取其頁開了。我們可以在ajax調用上觸發對「/ site/toast」的請求,這可以使Ajax上述小部件在當前url上發出ajax請求嗎?

由於沒有html「a」標籤,因爲在窗口小部件生成的html裏面沒有任何「form」標籤,這是否正確使用pjax?

http://localhost:8081/about-us?_pjax=%23new-alert 
  • Pjax的形式

    此外,如果我們結束內部Pjax活動表格,我們如何確保沒有除容器形式的標籤或嵌套表觸發一個Pjax請求?

回答

0

我從PHP中刪除,呼籲pjax並提出如下警示 -

<div id="new-alert"> 

     <?= \odaialali\yii2toastr\ToastrFlash::widget([ 
        'options' => [ 
         'positionClass' => 'toast-bottom-full-width', 
         //'progressBar' => true, 
         'timeOut' => 6000, 
         'extendedTimeOut' => 2000      
        ] 
     ]); ?> 

</div> 

相反,我正在pjax從JavaScript調用如下 -

$.pjax({url: encodeURI(baseUri + "site/toast"), container: '#new-alert', push: false}) 

public function actionToast() 
{    
    if(Yii::$app->request->getHeaders()->has('X-PJAX')) 
    { 
     return $this->renderAjax('//common/alert'); 
    } 
    else 
    { 
     return $this->redirect(Yii::$app->request->referrer);   
    } 
} 

$ .pjax。如果當前網址中有一些網址,則重新加載之前會檢索其他敬酒。以上解決方案只獲得與ajax相關的敬酒。