hello I want to delete a Django object using AJAX or JavaScript with confirm message on clicking delete but I don't know how to complete AJAX request.
views.py
def delete(request,id):
try:
inta = work.objects.get(pk=id)
inta.delete()
except:
pass
return HttpResponseRedirect(reverse('home'))
urls.py
url(r'^delete/(?P<id>\d+)/$',views.delete, name='delete')
html :
{& for app in apps &}
<p>{{ app.item0 }}</p>
<p>{{ app.item1 }}</p>
<p>{{ app.item2 }}</p>
<button data-object-id="{{ app.id }}">remove</button>
{% endfor %}
$('button').on('click', function(){
var confirmation = confirm("are you sure you want to remove the item?");
if (confirmation) {
// execute ajax
alert('removed');
}
})