-
-
Save videlais/a4d3c299bddfb624413c1d558d89bf46 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Assume this is part of a larger plugin project | |
// Enqueue our AJAX script | |
// Tell WordPress to make sure jQuery is also loaded as part of our dependency array | |
wp_enqueue_script( 'ajax-script', plugins_url( '/js/test.js', __FILE__ ), array('jquery') ); | |
// Add 'wp_ajax' tied to the "example_function" action | |
add_action( 'wp_ajax_example_function', 'example_function_callback' ); | |
// Callback function for the wp_ajax_example_function action | |
function example_function_callback() { | |
// Echo back the some_value passed to it | |
echo $_POST["some_value"]; | |
// Die gracefully to guarantee proper return response | |
wp_die(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment