0👍
✅
The condition in one event handler doesn’t necessarily work in the second event handler, you have to join it all in one event handler :
$('.type_delete').on('click', function (e) {
e.preventDefault();
if (confirm("Are you sure want to delete record?")) {
var csrf_token = $("#csrf_token").val(),
id = this.id;
$.ajax({
data: {
csrfmiddlewaretoken: '{{'+csrf_token+'}}',
delete: id
},
type: 'POST',
url: '/setting/type/',
cache: false
});
}
});
1👍
By the time your confirmation box is displayed, the call to second function is already underway. You need to define the second function as another independent function and then call it from within first one.
Here is an example:
$('.delete').click(function (e) {
e.preventDefault();
if (confirm("Are you sure want to delete record?")) {
doDelete($(this).attr('id'))
}
});
function doDelete(elemId) {
var csrf_token = $("#csrf_token").val();
var id = elemId;
$.ajax({ // create an AJAX call...
data:{
csrfmiddlewaretoken: ('{{csrf_token}}'),
delete:id
},
type:'POST',
url: '/setting/type/', // the file to call
cache:false,
success: function() { // on success..
window.location.href = window.location;
});
}
- [Answer]-How to redirect the user back to the requested page after logging user in django?
- [Answer]-Separate member and guest template content in django
- [Answer]-Periodic task using celery to delete a queryset result
- [Answer]-Django filter exclude with in and case senstive
- [Answer]-Django form submit not working
Source:stackexchange.com