Use base.js CSRF auto-injection for AJAX requests

- Remove manual CSRF handling from JavaScript
- base.js already intercepts fetch() and adds X-CSRF-TOKEN automatically
- Simplify JavaScript code for subtasks operations
This commit is contained in:
2026-02-08 15:51:06 +00:00
parent 1c98327de3
commit e85390be84
2 changed files with 3 additions and 33 deletions
+3 -21
View File
@@ -227,13 +227,6 @@
{% block scripts %}
{{ parent() }}
<script>
function getCsrfData() {
return {
token: '{{ csrf_token() }}',
hash: '{{ csrf_hash() }}'
};
}
function addSubtask(event, taskId) {
event.preventDefault();
const form = event.target;
@@ -242,15 +235,12 @@ function addSubtask(event, taskId) {
if (!title) return;
const csrf = getCsrfData();
fetch(`/tasks/${taskId}/subtasks`, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `title=${encodeURIComponent(title)}&${csrf.token}=${csrf.hash}`
body: 'title=' + encodeURIComponent(title)
})
.then(response => response.json())
.then(data => {
@@ -299,15 +289,11 @@ function updateSubtasksCount() {
}
function toggleSubtask(taskId, subtaskId) {
const csrf = getCsrfData();
fetch(`/tasks/${taskId}/subtasks/${subtaskId}/toggle`, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `${csrf.token}=${csrf.hash}`
}
})
.then(response => response.json())
.then(data => {
@@ -328,15 +314,11 @@ function toggleSubtask(taskId, subtaskId) {
function deleteSubtask(taskId, subtaskId) {
if (!confirm('Удалить подзадачу?')) return;
const csrf = getCsrfData();
fetch(`/tasks/${taskId}/subtasks/${subtaskId}/delete`, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `${csrf.token}=${csrf.hash}`
}
})
.then(response => response.json())
.then(data => {