Answer the question
In order to leave comments, you need to log in
Django/ajax how to display new data on current page without page refresh?
Hello.
I make a function:
A person clicks on a button (link), the number of likes increases by one. Now I made this function through Ajax, but the problem is that the number of likes is increasing, but this can only be seen after the page is refreshed. How to make the update go instantly?
Button/Link:
<a id="upvideolike" class="article_social_thumb" href="">{{ videoitem.get_plus }}</a> #get_plus - число лайков.
<script type="text/javascript">
$('#upvideolike').click(function(e){
e.preventDefault();
$.ajax({
url: '{% url "upvideolike" videoitem.id %}',
data:{
},
sucess:function(){
}
})
});
</script>
def upvideolike(request, add_id):
if request.user.is_authenticated():
video_item = Video.objects.get(id = add_id)
user_tags = User.objects.filter(users_video_main = add_id)
current_user = request.user
if current_user not in user_tags:
try:
video_item = Video.objects.get(id = add_id)
video_item.thumbnumber +=1
video_item.likedone.add(current_user)
video_item.save()
return HttpResponse()
except ObjectDoesNotExist:
return HttpResponse()
else:
return HttpResponse()
else:
return HttpResponse()
def video(request, video_id):
videoitem = Video.objects.get(id = video_id)
context = {
"videoitem" : videoitem,
}
return render(request, 'faceset/videopage.html', context)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question