python - Is it possible to have 'Save' / 'Delete' anchors with hidden inputs -


don't know if possible or not. i'm trying make when user clicks save or delete anchor, doesn't redirect anywhere. guess i'm asking is, possible hidden input recognize anchor if input , send view?

example: template: * updated !

<a class="delete" href="javascript:void(0)">delete</a> 

django view: (what started with)

@login_required def edit_box(request):     if 'edit' in request.post:          deletes = [int(item) 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) 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 going wrong?

sure! don't need use hidden input.

you can make sure anchor tag doesn't go anywhere adding

href="javascript:void(0)"

which "href" value should use javascript links, "#" or "javascript:void(0)"?

additionally, need light javascript work.

this include:

1) adding onclick event anchor

2) when anchor clicked associated item.id

3) action want perform ie. save or delete

4) make ajax request django app item.id , action.

5) response!

this allows user perform actions without relying on page refreshes. ajax crucial concept , worth effort of learning. http://www.w3schools.com/ajax/default.asp

watch out posting data through ajax csrf middleware. can tricky. https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -