Skip to content

Instantly share code, notes, and snippets.

@autocircled
Last active October 9, 2022 10:57
Show Gist options
  • Save autocircled/12ad7019e2e0b909dbb938c47363b643 to your computer and use it in GitHub Desktop.
Save autocircled/12ad7019e2e0b909dbb938c47363b643 to your computer and use it in GitHub Desktop.
// alpha JS request // no jQuery
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#Example_POST
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
var request = new XMLHttpRequest();
request.open('POST', fpm_ajax.ajax_url, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
request.onload = function () {
if (this.status >= 200 && this.status < 400) {
// If successful
console.log(this.response);
} else {
// If fail
console.log(this.response);
}
};
request.onerror = function() {
// Connection error
};
request.send('action=work_hour_form_handler&work_hours_start=' + document.getElementById('work-hours--start').value + '&work_hours_end=' + document.getElementById('work-hours--end').value);
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment