Modify AJAX to be able reset rating

Sep 13, 2013 at 11:24 AM
Hi,
I am using modified RateIt code with MODX extra Lexrating.
Example: HERE

The vote is send via ajax after click. I need to modify the code to be able reset the rating (reset button dissappear after voting), or send the rating not after clicking on icon, but on form submit.
 $('.rateit').bind('rated reset', function (e) {
        var ri = $(this);
        var value = ri.rateit('value');
        var objID = ri.data('objectid');
        var extended = ri.data('extended');
        ri.rateit('readonly', false);
        $.ajax({
            url: 'assets/components/lexrating/connector.php',
            data: {
                action: 'web/count/set',
                id: objID,
                Count: value,
                Extended: extended
            },
            type: 'POST',
            cache: false,
            success: function (data) {
                var response = JSON.parse(data);
                if (response.object.value) {
                    ri.rateit('value', response.object.value);
                    var readonly = (response.object.allowedToVote === true) ? false : true;
                    ri.rateit('readonly', readonly);
                    var counterHolder = '#count_' + ri.prop('id');  
                    $(counterHolder).text(response.object['total.voters']); 
                    location.reload();
                }
            },
            error: function (jxhr, msg, err) {
                console.log('jxhr, msg, err', jxhr, msg, err)
            }
        });

    });
Coordinator
Oct 18, 2013 at 2:05 AM
Just remove the lines dealing with "readonly" from the code you posted. This should take care of that.