Support Center

Frequently asked questions and support documentation for RatingWidget.

  • >
  • Do you have a refresh code for Ajax loaded content?

Do you have a refresh code for Ajax loaded content?

In order to refresh / re-render the ratings on the page all you need to do is execute the following JavaScript line.

RW.render(null, true);

You can add the following code snippet right before your closing </body> tag (requires jQuery support) and it will automatically do the job.

<script type="text/javascript">
    (function($){
        $(document).ajaxSuccess(function() {
            setTimeout(function(){
                if ("undefined" !== typeof(RW))
                    RW.render(null, true);
            }, 500);
        });
    })(jQuery);
</script>

If you care about efficiency, call this method only after you add new ratings’ HTML containers (not on every Ajax call).

Using the WordPress Plugin?

To add the snippet right in your WordPress’ footer, add the following code to your theme’s functions.php file:

    /* Append ratings render-er after ajax call.
    ------------------------------------------*/
    function rw_render_ratings_after_ajax()
    {
?>
<script type="text/javascript">
    (function($){
        $(document).ajaxSuccess(function() {
            setTimeout(function(){
                if ("undefined" !== typeof(RW))
                    RW.render(null, true);
            }, 500);
        });
    })(jQuery);
</script>
<?php        
    }

    add_action('wp_footer', 'rw_render_ratings_after_ajax');

Leave a Comment

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>