Skip to content

Instantly share code, notes, and snippets.

@mckernanin mckernanin/functions.php
Last active Aug 6, 2016

Embed
What would you like to do?
WordPress Admin AJAX Example
<?php
add_action('wp_ajax_action_name', 'callback_function');
add_action('wp_ajax_nopriv_action_name', 'callback_function');
function callback_function() {
echo 'stuff to return';
die();
}
var data = {
action: 'action_name'
};
$.ajax({
url: ajaxurl, // http://yoursite.com/wp-admin/admin-ajax.php
type: "POST",
data: data,
async : false,
success: function(data){
do_stuff();
},
fail: function(){
error_message();
}
});
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.