   method: 'POST',
    })
    .then(response => response.json())
    .then(data => {
        console.log(data);

        // Re-enable the button after a successful response
        captureButton.disabled = false;

        // Refresh preview image
        const filename = `/static/gallery/snapshot/pimage_preview_${camera_num}.jpg`;
        document.getElementById(`pimage_preview_${camera_num}`).src = `${filename}?${new Date().getTime()}`;
    })
    .catch(error => {
        console.error('Error capturing ph