Skip to content

Instantly share code, notes, and snippets.

@kraigh
Created September 20, 2016 00:56
Show Gist options
  • Save kraigh/e944a2817257bdd9f0b065d511acb0c0 to your computer and use it in GitHub Desktop.
Save kraigh/e944a2817257bdd9f0b065d511acb0c0 to your computer and use it in GitHub Desktop.
jQuery(document).ready(function ($) {
$.getJSON("http://kraigh.com/cse104/reviews.php", function(data) {
$.each(data, function(index, val) {
console.log(val);
var starsHtml = '';
for (var i = 0; i < 5; i++) {
// subtract 1 from rating since i starts at 0
if (i > (parseInt(val.rating, 10) - 1)) {
starsHtml += '<span class="glyphicon glyphicon-star-empty" aria-hidden="true"></span>';
} else {
starsHtml += '<span class="glyphicon glyphicon-star" aria-hidden="true"></span>';
}
}
$('#reviews-list').append('<li id="review-'+index+'" class="list-group-item row"></li>');
$('#review-'+index).append('<div class="col-md-3 review-name">'+val.name+'<br />'+starsHtml+'</div>');
$('#review-'+index).append('<div class="col-md-2 review-menu">'+val.menu+'</div>');
$('#review-'+index).append('<div class="col-md-3 review-greeted"><b>Was greeted when:</b> '+val.greeted+'</div>');
$('#review-'+index).append('<div class="col-md-4 review-comments"><b>Comments:</b> '+val.comments+'</div>');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment