Code: Select all
document.addEventListener('click', function(event) {
if (event.target.classList.contains('book-now')) {
let jobId = event.target.dataset.jobId; // Get job ID from button
let row = event.target.closest('tr');
fetch(jobBookingAjax.ajaxurl, { // Make sure this prints correctly in console
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
action: 'book_job',
nonce: jobBookingAjax.nonce,
job_id: jobId
})
})
.then(response => response.json())
.then(data => {
console.log(JSON.stringify(data));
if(data.success) {
alert(data.data.message);
row.remove();
}else{
alert("Error: " + data.data.message);
}
})
.catch(error => console.error('Error:', error));
}
});