-
-
Save alexmangini/28719a8c8e100d931fe4ac4a395e43fa to your computer and use it in GitHub Desktop.
Star rating script code example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$('.driver-rating').barrating({ | |
theme: 'fontawesome-stars', | |
initialRating: "<?php echo $averageRating; ?>", | |
showSelectedRating: true, | |
// onSelect is what triggers the saving of the rating. | |
onSelect: function(value, text, event) { | |
// Get element id by data-id attribute | |
var el = this; | |
var el_id = el.$elem.data('id'); | |
// rating was selected by a user | |
if (typeof(event) !== 'undefined') { | |
var split_id = el_id.split("_"); | |
var postid = split_id[1]; // postid. | |
alert(postid + ' ' + value); | |
// AJAX Request | |
$.ajax({ | |
url: "<?php echo $ajax_url; ?>", | |
type: 'post', | |
action: 'my_function_name', | |
data: {postid:postid,rating:value}, | |
dataType: 'json', | |
success: function(data) { | |
// Update rating. | |
var therating = data['rating']; | |
$('#avgrating_'+postid).text(therating); | |
} | |
}); | |
} | |
} // end onSelect | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment