Created
July 7, 2016 09:38
-
-
Save ragowthaman/5035c49d940f104d0f97b52dd72d4b81 to your computer and use it in GitHub Desktop.
How to delete a list element via ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def delete_practice(request): | |
| if request.is_ajax and request.POST: | |
| kb_practice_id = request.POST.get('kb_practice_id') | |
| Practice.objects.get(id=kb_practice_id).delete() | |
| return HttpResponse(json.dumps({}), content_type="application/json") | |
| else: | |
| raise Http404 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function delete_practice(){ | |
| $(".actions .delete-practice").click(function (){ | |
| var isGood=confirm('Irreversible Action! Are you sure want to delete this PRACTICE from KB once for all?'); | |
| if (isGood) { | |
| var $row = $(this).parents(".practice-row"); | |
| var $practice_id = $(this).parents(".practice-row").find(".practice-id input").val(); | |
| console.log("$practice_id id") | |
| console.log($practice_id) | |
| console.log($row) | |
| console.log("$practice_id id") | |
| //delete from database as well | |
| $.ajax({ | |
| type: "POST", | |
| url: "/knowledgebase/delete/practice/", | |
| dataType: "json", | |
| data: {"kb_practice_id": $practice_id}, | |
| success: function (data) { | |
| //console.log("all good"); | |
| //remove it from screen if success in deleting at the database | |
| $($row).remove(); | |
| }, | |
| error: function (data, errmsg, err) { | |
| console.log("something wrong in deleting practice"); | |
| console.log(data); | |
| console.log(errmsg); | |
| console.log(err) | |
| } | |
| }); | |
| } | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <TD> | |
| <a href="/knowledgebase/delete/practice/{{ practice.id }}/">Delete Practice</a> | |
| </TD> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url(r'^delete/practice/', 'knowledgebase.ajax.delete_practice'), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment