Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created September 6, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/61bd05c60b40d9f3ecd9eb81e5cb3f86 to your computer and use it in GitHub Desktop.
Save tommcfarlin/61bd05c60b40d9f3ecd9eb81e5cb3f86 to your computer and use it in GitHub Desktop.
[jQuery] The Why and How of Custom jQuery Events
$button.on('click', function(evt) {
evt.preventDefault();
$(document).trigger('acme.ajax.processing');
$.get(ajaxurl, {
// Your action and security measures here.
}, function(response) {
// Your response behavior here.
});
});
$(document).on('acme.ajax.processing', function() {
$button.attr('disabled', 'disabled');
});
$button.on('click', function(evt) {
evt.preventDefault();
$(document).trigger('acme.ajax.processing');
$.get(ajaxurl, {
// Your action and security measures here.
}, function(response) {
// Your response behavior here.
})
.done(function() {
$(document).trigger('acme.ajax.complete');
});
});
$(document)
.on('acme.ajax.processing', function() {
$button.attr('disabled', 'disabled');
})
.on('acme.ajax.complete', function() {
$button.removeAttr('disabled');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment