yiisoft / jquery-pjax

pushState + ajax = pjax
http://pjax.herokuapp.com
MIT License
144 stars 40 forks source link

Timeout property has no effect #40

Closed matperez closed 8 years ago

matperez commented 8 years ago

Hello!

I noticed that the timeout option has no effect on the behavior of the widget

            "name": "bower-asset/yii2-pjax",
            "version": "v2.0.5",
            "source": {
                "type": "git",
                "url": "https://github.com/yiisoft/jquery-pjax.git",
                "reference": "6818718408086db6bdcf33649cecb86b6b4f9b67"
            },

I'm using it this way

    <?php \yii\widgets\Pjax::begin([
        'id' => 'widget',
        'timeout' => 3000,
    ]) ?>

It looks fine in the page source code

    jQuery(document).pjax("#widget a", "#widget", {"timeout":3000,"push":true,"replace":false,"scrollTo":false});

But the option has no effect unless I set it globally via $.pjax.defaults.timeout = 3000;

Could it be an issue?

SilverFire commented 8 years ago

Basic app template:

SiteController.php

diff --git a/controllers/SiteController.php b/controllers/SiteController.php
index 33f6227..4c497a8 100644
--- a/controllers/SiteController.php
+++ b/controllers/SiteController.php
@@ -95,6 +95,12 @@ class SiteController extends Controller
         ]);
     }

+    public function actionSleep()
+    {
+        sleep(3);
+        return $this->renderAjax('about');
+    }
+
     public function actionAbout()
     {
         return $this->render('about');

view about.php

diff --git a/views/site/about.php b/views/site/about.php
index 752342c..18220b9 100644
--- a/views/site/about.php
+++ b/views/site/about.php
@@ -17,4 +17,8 @@ $this->params['breadcrumbs'][] = $this->title;
     <?= Yii::t('app', 'ru-RU тест') ?>

     <code><?= __FILE__ ?></code>
+
+    <?php \yii\widgets\Pjax::begin(['timeout' => 3000]); ?>
+        <a href="/site/sleep">click</a>
+    <?php \yii\widgets\Pjax::end(); ?>
 </div>

This code works as expected: clicking on link triggers PJAX request, the client side waits 3 seconds waiting for the response, then navigates to /site/sleep URL with full page reload. When I decrease sleep time in the controller action, PJAX loads the response without page reload.

How to reproduce the problem?

matperez commented 8 years ago

Sorry. It's my fault.

I've used $.pjax.reload to reload the container. Apparently it uses the default timeout value.