最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - yii2: updaterefreshreload a page using Pjax different from requesting page - Stack Overflow

programmeradmin0浏览0评论

I have asked this question, but I think that wasn't clear enough so I am putting it differently. I have a _form.php page and a grid-view(index.php)page.

I am sending a Pjax request from _form.php and want to update/refresh the grid-view(index.php)page.

on top my _form.php I am having this code.

<?php

    $this->registerJs(
       '$("document").ready(function(){ 
            $("#new_medicine").on("pjax:end", function() {
                $.pjax.reload({container:"#medicine"});  //Reload GridView
            });
        });'
    );
    ?>

Now the container "#medicine" is not on _form.php page, but grid-view(index.php) page. So how can I modify the above code so that it updates/refresh the container "#medicine" in index.php page.

I think I have explained the situation correctly. please tell me, if more information is needed.

Thanks.

I have asked this question, but I think that wasn't clear enough so I am putting it differently. I have a _form.php page and a grid-view(index.php)page.

I am sending a Pjax request from _form.php and want to update/refresh the grid-view(index.php)page.

on top my _form.php I am having this code.

<?php

    $this->registerJs(
       '$("document").ready(function(){ 
            $("#new_medicine").on("pjax:end", function() {
                $.pjax.reload({container:"#medicine"});  //Reload GridView
            });
        });'
    );
    ?>

Now the container "#medicine" is not on _form.php page, but grid-view(index.php) page. So how can I modify the above code so that it updates/refresh the container "#medicine" in index.php page.

I think I have explained the situation correctly. please tell me, if more information is needed.

Thanks.

Share Improve this question edited Jan 5, 2015 at 21:00 Pawan asked Jan 5, 2015 at 20:47 PawanPawan 3,86417 gold badges52 silver badges87 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Try using $this::POS_READY instead of wrapping your code in $("document").ready(function(){})

$js = '$("#new_medicine").on("pjax:end", function() {
           $.pjax.reload({container:"#medicine"});  //Reload GridView
       });'

$this->registerJs($js, $this::POS_READY);

EDIT

Apparently you want to reload the gridview that is open on another client's index.php after data is inserted using _form.php.

It isn't possible to send jQuery mands to another client (browser) and have it executed.

You can for example reload the gridview on the index.php every x seconds or minutes.

 $js = 'function refresh() {
     $.pjax.reload({container:"#medicine"});
     setTimeout(refresh, 5000); // restart the function every 5 seconds
 }
 refresh();';
 $this->registerJs($js, $this::POS_READY);
发布评论

评论列表(0)

  1. 暂无评论