The AJAX callback doesn’t take any parameters, you have to get them from the request using $_GET
/$_POST
/$_REQUEST
(depending on how you have your javascript set up). This means that to get get mix_name
from your POST
you would use $_POST['mix_name']
. Including the add_action( 'wp_ajax_...
calls from your code would be good if you have future questions as well, I had to go to the GitHub page to see how you had it set up – you’re also missing single quotes around add_action( 'wp_enqueue_scripts', 'ajaxglitch_player_enqueuescripts' );
which PHP can figure out, but it will try it as a constant first. This is what the config should look like:
function ajaxglitch_player_enqueuescripts() {
wp_enqueue_script('ajaxglitch_player', glitch_player_URL.'/js/glitch_player.js', array('jquery'));
// access ajax url on the front end as ajaxglitch_playerajax.ajaxurl
wp_localize_script( 'ajaxglitch_player', 'ajaxglitch_playerajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
add_action( 'wp_enqueue_scripts', 'ajaxglitch_player_enqueuescripts' );
// front end ajax handler
add_action( 'wp_ajax_nopriv_ajaxglitch_player_ajaxhandler', 'ajaxglitch_player_ajaxhandler' );
// admin ajax handler
add_action( 'wp_ajax_ajaxglitch_player_ajaxhandler', 'ajaxglitch_player_ajaxhandler' );
function ajaxglitch_player_ajaxhandler(){
$mix_name = isset( $_POST['mix_name'] )? $_POST['mix_name'] : false;
var_dump( "The mix_name is $mix_name" ); // this will probably break the AJAX response
error_log( "The mix_name is $mix_name" ); // write it to the error_log too.
}