AJAX button run function

In order to make this work as you expect, you need to add the following lines in your constructor (depending on the requirements you have)

add_action( 'wp_ajax_myfunction', array($this, 'myfunction') );
add_action( 'wp_ajax_nopriv_myfunction', array($this, 'myfunction') );

Note that wp_ajax_nopriv_myfunction executes for users that are not logged in. The other executes for logged in users only.

You also need to just check that in your JS, ajaxurl returns your ajax URL.

If not, you’ll need to expose that URL for usage in your JS. You can do that by following the codex here: https://codex.wordpress.org/Function_Reference/wp_localize_script

You will need to call wp_die(); at the end of your PHP function as well.