I tried to research but couldn't find a way to handle META requests in Django with Ajax. Refreshing a page everytime kind of destroys the UX. So if the code is something like this:
template
<a href="/like/?id={{ car.id }}" ># of likes: {{ car.likes }}</a>
views.py
def like_page(request):
if 'id' in request.GET:
id = request.GET['id']
car = Cars.objects.get(id=id)
car.likes += 1
car.save()
if 'HTTP_REFERER' in request.META:
return HttpResponseRedirect(request.META['HTTP_REFERER'])
return HttpResponseRedirect('/')
So the template sends the id of the object, and in the views it increments the like by 1. everytime this happens. Now the problem is that without Ajax it reloads the page everytime it happens. I am a backend developer, so I have almost no experience with jQuery and Ajax, so I have no clue how to approach this problem.
Any help would be appreciated. Thanks :)