How To Create a WordPress Plugin for AJAX Support

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/* Plugin Name: Your New Plugin Plugin URI: http://www.yoursite.com Version: 1.0 Description: Your new plugin's description... Author: Your Name Author URI: http://www.yoursite.com License: Copyright 2013 Your Name (email : you@yoursite.com) */ add_action('wp_ajax_nopriv_ajaxTest', 'ajaxTest'); add_action('wp_ajax_ajaxTest', 'ajaxTest'); function ajaxTest() { ob_clean(); // generate the response $response = json_encode( array( 'status' => 0, 'msg' => 'AJAX TEST SUCCESS!' ) ); // response output header( "Content-Type: application/json" ); echo $response; exit; } Call with: $ajaxurl = admin_url("admin-ajax.php") $ajaxurl?action=ajaxTest // |
Happy Coding!
Leave Your Comment
All fields marked with "*" are required.