Last active
August 6, 2016 18:45
-
-
Save mckernanin/95b593070796107e408a3aa895df4aa5 to your computer and use it in GitHub Desktop.
WordPress Admin AJAX Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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