Don't know if this is possible or not. But I'm trying to make it so when a user clicks save or delete anchor, it doesn't redirect anywhere. I guess what I'm asking is, is it possible for a hidden input to recognize the anchor as if it were an input and send it to the view?
Example: Template: * Updated !
<a class="delete" href="javascript:void(0)">delete</a>
Django View: (what I started with)
@login_required
def edit_box(request):
if 'edit' in request.POST:
deletes = [int(item) for item in request.POST.getlist('delete')]
yadda yadda delete code
...
return render_to_response('cart/boxcart.html', context, context_instance=RequestContext(request))
Django View: *Updated !
@login_required
def edit_box(request):
profile = get_object_or_404(Profile, user=request.user)
item_in_profile = Item.objects.filter(profile=profile)
deletes = [int(item_in_profile) for item_in_profile in request.POST.getlist('delete')]
item_in_profile.filter(id__in=deletes).delete()
item_in_profile.save()
return render_to_response('cart/boxcart.html', context, context_instance=RequestContext(request))
ajax attempt:
$(".delete").click(
function(){
$.ajax({
type: "GET",
url: "/profile/delete/{{ item???}}/",
dataType: "json",
success: function(data){
$("{{ item }}").fadeOut(300, function() { $("{{ item }}").remove() });
}
});
});
Or am I going about this all wrong?