Attend event form with ajax

First of all. You’ll need to follow the ajax best practices in WordPress. That means, add the right actions for your functions and call them also with the admin ajax url.

So your jQuery ajax should call the admin_url, and you’ll need to send along an ‘action’ data in this example, the name of the action: ‘subscribe’; (wp_ajax_subscribe minus the wp_ajax_ ). You can include that with a hidden input field called with name ‘action’ and value ‘subscribe’, so you serialize function picks it up from the submit event.

url: '<?php echo admin_url( 'admin-ajax.php' )?>',

add_action( 'wp_ajax_subscribe', 'ja_ajax_subscribe' );
add_action( 'wp_ajax_nopriv_subscribe', 'ja_ajax_subscribe' );

function ja_ajax_subscribe(){

   $result="some data";

   wp_send_json_success($result);
}