Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Star Rating plugin - select in callback causes infinite loop

Using the jQuery Star Rating plugin everything works well until I select a star rating from the rating's callback handler. Simple example:

$('.rating').rating({
    ...

    callback: function(value){ 
        $.ajax({
            type: "POST",
            url: ...
            data: {rating: value},
            success: function(data){
                $('.rating').rating('select', 1);
            }
        });
    } 
});

I'm guessing this infinite loop occurs because the callback is fired after a manual 'select' as well. Once a user submits their rating I'd like to 'select' the average rating across all users (this value is in data returned to the success handler).

How can I do this without triggering an infinite loop?

like image 511
Growth Mindset Avatar asked Feb 26 '26 11:02

Growth Mindset


1 Answers

They have terrible documentation.

Digging through the source code, you will find that the "select" function takes an additional parameter wantCallBack. So set that to false:

$('.rating').rating('select', 1, false);
like image 155
David Tang Avatar answered Mar 01 '26 00:03

David Tang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!