Been looking for some help changing a jQuery.ajax()
request into vanilla XMLHttpRequest
for WordPress, but not really finding what I want. Can anyone help me reformat the below into vanilla JavaScript XMLHttpRequest
?
$.ajax({
data: {
'action': 'work_hour_form_handler',
'work_hours_start': document.getElementById('work-hours--start').value,
'work_hours_end': document.getElementById('work-hours--end').value,
'break-hours_start': document.getElementById('break-hours--start').value,
'break-hours_duration': document.getElementById('break-hours--duration').value,
'working_days': document.getElementById('working-days').value
},
headers: {},
method: 'post',
url: fpm_ajax.ajax_url
}).done(function (data) {
// If successful
console.log(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
// If fail
console.log(textStatus + ': ' + errorThrown);
});
wp_localize_script( 'feelya_pm_scripts', 'fpm_ajax', [ 'ajax_url' => admin_url( 'admin-ajax.php' ) ] );