Code Snippet:
$('.delete').click(function() {
if (confirm("Are you sure you want to delete?")) {
var csrf_token = $("#csrf_token").val();
$.ajax({ // performing an AJAX call...
data:{
csrfmiddlewaretoken: ('{{csrf_token}}'),
delete:true
},
type:'POST',
url: '/feed_list/',
cache:false,
success: function() {
window.location.href = window.location;
}
});
return false;
}
});
In this JavaScript function, I am calling a method in views.py that performs a delete function. The delete function is functioning properly, however my issue lies in having this JavaScript function on the current HTML page. When attempting to move this function to a static folder -> scripts -> custom.js, it results in a 403 error page with the message
CSRF verification failed. Request aborted.
, although I am passing the CSRF token in both the form and the JavaScript. I am seeking suggestions on how to resolve this dilemma.