init
This commit is contained in:
36
backend/globalstaticfiles/js/index.js
Normal file
36
backend/globalstaticfiles/js/index.js
Normal file
@@ -0,0 +1,36 @@
|
||||
document.getElementById('sendEmailBtn').addEventListener('click', function () {
|
||||
const recipient = document.getElementById('email-recipient').value;
|
||||
|
||||
fetch(`${window.location.origin}/test/email`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken'),
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ recipient: recipient })
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
alert('Success: ' + JSON.stringify(data));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Failed to send request.');
|
||||
});
|
||||
});
|
||||
|
||||
// Helper function to get CSRF token from cookies
|
||||
function getCookie(name) {
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (const cookie of cookies) {
|
||||
const trimmed = cookie.trim();
|
||||
if (trimmed.startsWith(name + '=')) {
|
||||
cookieValue = decodeURIComponent(trimmed.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
Reference in New Issue
Block a user