我问过这个问题,但我认为这还不够清楚,所以我换个说法。我有一个_form.php页面和一个网格视图(索引.php)页面。
我正在从_form.php发送 Pjax 请求,并希望更新/刷新网格视图(索引.php)页面。
在我的_form.php上面,我有这段代码。
<?php
$this->registerJs(
'$("document").ready(function(){
$("#new_medicine").on("pjax:end", function() {
$.pjax.reload({container:"#medicine"}); //Reload GridView
});
});'
);
?>
现在容器"#medicine"
不在页面上_form.php而是网格视图(索引.php)页面上。那么我如何修改上面的代码,以便它更新/刷新 index.php 页面中的容器"#medicine"
。
我想我已经正确地解释了情况。 如果需要更多信息,请告诉我。
谢谢。
尝试使用 $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
上打开的网格视图。
将jQuery命令发送到另一个客户端(浏览器)并执行它。
例如,您可以每 x 秒或每分钟重新加载一次index.php
上的网格视图。
$js = 'function refresh() {
$.pjax.reload({container:"#medicine"});
setTimeout(refresh, 5000); // restart the function every 5 seconds
}
refresh();';
$this->registerJs($js, $this::POS_READY);