Skip to content

Instantly share code, notes, and snippets.

@danielhomer
Created October 6, 2015 14:45
Show Gist options
  • Save danielhomer/9a3c82ff1f4fdc18a209 to your computer and use it in GitHub Desktop.
Save danielhomer/9a3c82ff1f4fdc18a209 to your computer and use it in GitHub Desktop.
(function($) {
$.ajax({
url: ajaxurl,
action: 'my_wp_ajax_action'
})
.success(function(response) {
if (typeof response.success === 'undefined') {
// undefined error
} else if (response.success === false) {
// error (sent with wp_send_json_error)
} else if (response.success === true ) {
// success (sent with wp_send_json_success)
} else {
// something weird has happened
}
})
.fail(function() {
// network issues / no response etc.
})
.always(function() {
// always do this, whether the request was successful or not
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment