Django AJAX "Uncaught TypeError: $(...).attrs is not a function"
Когда я касаюсь тега якоря, чтобы отправить данные, я получаю эту ошибку Uncaught TypeError: $(...).attrs is not a function.
Я сделал console.log($(this)), на выходе [объект Object].
Я также сделал console.log(JSON.stringify($(this))), вывод {"0":{}, "length":1}
HTML, Мой тег якоря:
<a href="{% url 'my-site' slug=object.anotherObject.slug %}" id="update-done"
data-donePk="{{object.pk}}"
>Done</a>
JS, Мой AJAX
$(document).on('click', '#update-done', function(e) {
e.preventDefault()
let confirmation = confirm("Are you sure you want to make done?");
if (confirmation) {
console.log("this: " + JSON.stringify($(this)))
alert($(this))
// Error comes from this line below
var objectPk = $(this).attrs('data-donePk')
var makeDone = 'post'
$.ajax({
url: "/site/make_done/",
data: {
'csrfmiddlewaretoken': "{{ csrf_token }}",
"objectPk":objectPk,
"makeDone": makeDone,
},
type: "POST",
dataType: 'json',
cache: false,
success: function(data) {
console.log(data)
},
})
}
});