1

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.

Sumoanand
  • 8,835
  • 2
  • 47
  • 46

4 Answers4

0

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.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
TelFiRE
  • 462
  • 1
  • 6
  • 17
0

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

Community
  • 1
  • 1
Rabea
  • 1,938
  • 17
  • 26
0

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

  • Yes, there is something obvious missing. That PHP code is expanded when they request the page from the webserver, not when the Javascript is executed, so it will hold the values from before they voted. You will need some way of getting just the view via javascript to embed in the page. – ZoFreX Dec 06 '10 at 01:27
0

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

ZoFreX
  • 8,812
  • 5
  • 31
  • 51
  • Thanks ZoFreX - I tried this module out but can't find any way to connect it to refresh after voting... I'll try the code suggestion you suggested. – Steve Klein Dec 06 '10 at 17:23
  • I've done this exact thing with AJAX Views Refresh. It's not a super straight-forward, but it's totally the right way to go. – doublejosh Feb 24 '11 at 19:31