jQuery Star Rating plugin - select in callback causes infinite loop

Posted by Ian on Stack Overflow See other posts from Stack Overflow or by Ian
Published on 2011-01-07T01:29:37Z Indexed on 2011/01/07 1:54 UTC
Read the original article Hit count: 481

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery