Drupal - 我正在尝试使用 Fivestar 模块投票后刷新视图
我有一个在首页节点上进行投票的网站,每次投票后我需要更新同一节点上的视图。我目前在 page.tpl.php 中使用以下代码
<script type="text/javascript">
function fivestarResult(voteResult) {
$('div#fivestar-summary-'+voteResult.vote.id).html(voteResult.result.summary);
window.location = "http://www.mydomain.com/";
};
</script>
有没有办法直接刷新视图而不是刷新整个页面?我不太擅长 javascript,所以我有点迷失。
I have a site that has voting on the front page node, and I need to update a view on the same node after each vote. I'm currently using the following code in my page.tpl.php
<script type="text/javascript">
function fivestarResult(voteResult) {
$('div#fivestar-summary-'+voteResult.vote.id).html(voteResult.result.summary);
window.location = "http://www.mydomain.com/";
};
</script>
Is there a way to directly refresh the view instead of refreshing the whole page? I'm not very good in javascript so I'm a little lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这种情况下我可能会做的一个想法是 Ajax 再次调用视图并通过 JQuery 在单击事件上再次将其呈现在页面内。
拿这个例子,我想这会澄清更多
Drupal 6:渲染页面 tpl 文件中的视图 2 数据
An idea i may do in this kind of situation is to Ajax call the view again and render it inside the page again via JQuery on click event.
take this example , i guess this will clarify more
Drupal 6: Render Views 2 data in a page tpl file
谢谢拉贝,
听起来应该可行。我尝试了几种不同的方法,但无法得到它......
这段代码(在 page.tpl.php 中)是否有一些明显的我可能遗漏的东西?
非常感谢您的帮助
Thanks Rabe,
That sounds like it should work. I tried it a few different ways but couldn't get it to ...
Is there something obvious I could be missing from this code (in page.tpl.php)?
Thanks a lot for the help
与 Drupal 中的许多功能一样,可能已经编写了一个模块来执行此操作。 Ajax 视图刷新 听起来很有希望!
Like many things in Drupal, there may be a module already written to do this. Ajax views refresh sounds very promising!
我花了无数个小时调试视图,结果才意识到我启用了缓存并且正在查看旧结果。不同用户组的缓存也是分开的。因此,您可能需要手动刷新缓存才能更新,这对于 Ajax 来说可能是一个挑战。
I have spent countless hours debugging a view only to realize I had caching enabled and was looking at old results. The caches for different user groups are separate as well. So you may need to manually flush cache to get this to update, which might be a challenge with Ajax.