Solved by using Content-Type: application/x-www-form-urlencode with new URLSearchParams(body).toString() instead of JSON.stringify(body).
autosave-checklist.js
details.addEventListener('change', () => {
fetch(autosaveChecklist.ajaxUrl + '?action=autosave_checklist', {
method: 'POST',
body: new URLSearchParams({
action : 'autosave_checklist',
option: 'details-checkbox',
item: details.checked
}).toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.then(res => console.log(res))
.catch(err => console.error(err));;
});
socials.addEventListener('change', () => {
fetch(autosaveChecklist.ajaxUrl, {
method: 'POST',
body: new URLSearchParams({
action : 'autosave_checklist',
option: 'socials-checkbox',
item: socials.checked
}).toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.then(res => console.log(res))
.catch(err => console.error(err));
});
topicWheel.addEventListener('change', () => {
// console.log('topicWheel: ' + topicWheel.checked)
fetch(autosaveChecklist.ajaxUrl, {
method: 'POST',
body: new URLSearchParams({
action : 'autosave_checklist',
option: 'topic-wheel-checkbox',
item: topicWheel.checked
}).toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.then(res => console.log(res))
.catch(err => console.error(err));;
});
testimonials.addEventListener('change', () => {
// console.log('testimonials: ' + testimonials.checked)
fetch(autosaveChecklist.ajaxUrl, {
method: 'POST',
body: new URLSearchParams({
action : 'autosave_checklist',
option: 'testimonials-checkbox',
item: testimonials.checked
}).toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
.then(res => console.log(res))
.catch(err => console.error(err));;
});