yii2: update/refresh/reload 使用 Pjax 的页面与请求页面不同
yii2: update/refresh/reload a page using Pjax different from requesting page
我已经问过这个问题,但我认为还不够清楚,所以我换一种说法。我有一个 _form.php 页面和一个网格视图 (index.php) 页面。
我正在从 _form.php 发送 Pjax 请求并想要 update/refresh 网格视图(index.php)页面。
在我的 _form.php 之上,我有这个代码。
<?php
$this->registerJs(
'$("document").ready(function(){
$("#new_medicine").on("pjax:end", function() {
$.pjax.reload({container:"#medicine"}); //Reload GridView
});
});'
);
?>
现在容器 "#medicine"
不在 _form.php 页面上,而是在 grid-view(index.php) 页面上。那么我该如何修改上面的代码,使其 updates/refresh 容器 "#medicine"
in index.php page.
我想我已经正确地解释了情况。如果需要更多信息,请告诉我。
谢谢。
尝试使用 $this::POS_READY
而不是将代码包装在 $("document").ready(function(){})
中
$js = '$("#new_medicine").on("pjax:end", function() {
$.pjax.reload({container:"#medicine"}); //Reload GridView
});'
$this->registerJs($js, $this::POS_READY);
编辑
显然您想在使用 _form.php
插入数据后重新加载在另一个客户端 index.php
上打开的 gridview。
无法将 jQuery 命令发送到另一个客户端(浏览器)并执行。
例如,您可以每隔 x 秒或分钟重新加载 index.php
上的 gridview。
$js = 'function refresh() {
$.pjax.reload({container:"#medicine"});
setTimeout(refresh, 5000); // restart the function every 5 seconds
}
refresh();';
$this->registerJs($js, $this::POS_READY);
我已经问过这个问题,但我认为还不够清楚,所以我换一种说法。我有一个 _form.php 页面和一个网格视图 (index.php) 页面。
我正在从 _form.php 发送 Pjax 请求并想要 update/refresh 网格视图(index.php)页面。
在我的 _form.php 之上,我有这个代码。
<?php
$this->registerJs(
'$("document").ready(function(){
$("#new_medicine").on("pjax:end", function() {
$.pjax.reload({container:"#medicine"}); //Reload GridView
});
});'
);
?>
现在容器 "#medicine"
不在 _form.php 页面上,而是在 grid-view(index.php) 页面上。那么我该如何修改上面的代码,使其 updates/refresh 容器 "#medicine"
in index.php page.
我想我已经正确地解释了情况。如果需要更多信息,请告诉我。
谢谢。
尝试使用 $this::POS_READY
而不是将代码包装在 $("document").ready(function(){})
$js = '$("#new_medicine").on("pjax:end", function() {
$.pjax.reload({container:"#medicine"}); //Reload GridView
});'
$this->registerJs($js, $this::POS_READY);
编辑
显然您想在使用 _form.php
插入数据后重新加载在另一个客户端 index.php
上打开的 gridview。
无法将 jQuery 命令发送到另一个客户端(浏览器)并执行。
例如,您可以每隔 x 秒或分钟重新加载 index.php
上的 gridview。
$js = 'function refresh() {
$.pjax.reload({container:"#medicine"});
setTimeout(refresh, 5000); // restart the function every 5 seconds
}
refresh();';
$this->registerJs($js, $this::POS_READY);