Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.