25 lines
541 B
JavaScript
25 lines
541 B
JavaScript
const editForm = document.getElementById('editForm');
|
|
editForm.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(editForm);
|
|
const data = {};
|
|
|
|
for (const [key, value] of formData.entries()) {
|
|
data[key] = value;
|
|
}
|
|
|
|
const response = await fetch(`/api/v1/admin/route/${route}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(data)
|
|
});
|
|
|
|
if (response.ok) {
|
|
window.location.href = '/admin';
|
|
} else {
|
|
alert('Failed to update entry');
|
|
}
|
|
}); |