开发者

Drupal - I'm trying to refresh a view after voting with Fivestar module

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/";
 };
开发者_StackOverflow社区</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.


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


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)?

<script type="text/javascript">
    function fivestarResult(voteResult) {
    $('div#fivestar-summary-'+voteResult.vote.id).html(voteResult.result.summary);
    <?php
        $name = "comparison_view";
        print views_embed_view($name, $display_id = 'default');
    ?>
    };
</script>

Thanks a lot for the help


Like many things in Drupal, there may be a module already written to do this. Ajax views refresh sounds very promising!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜