I’m new to django and can’t find the way to refresh only the div and that the div shows me current rating with stars. My idea is that user can see average rating and rate something by clicking on the star, and after the click I want stars to show new average rating without refreshing the whole page.
This is the div:
<div id="rating">
<div class="movierating" id="o_{{ object.id }}">
<span style="display:none;">{{ object.rating_vote.get_rating }}</span>
{{ object.rating_vote.get_rating }}
</div>
</div>
And javascript is:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('.movierating').each(function(index){
$(this).raty({
readOnly: false,
path: "{{ STATIC_URL }}images/",
start: $(this).children("span:first").text(),
click: function(score, evt) {
var vote_url = "/rate/" + this.attr('id').substring(2) + "/" + score + "/";
var div = this.attr('id');
$.ajax({
url: vote_url,
success: function(){
alert('Vote successful!);
$('#rating').load('#rating');
},
});
}
});
});
});
</script>
With this code
$('#rating').load('#rating');
I get the whole page into the div, and when I use
$('#rating').load('# rating');
I get only value without the stars.