1) Is your function working?
First do a console.log( "it's working" );
inside your function and check it on your browser’s console.
If it’s not showing when you click, you must refactor your function.
2) Have you defined ajaxurl?
Unlike on the admin side, the ajaxurl javascript global does not get
automatically defined for you, unless you have BuddyPress or another
Ajax-reliant plugin installed. So instead of relying on a global
javascript variable, declare a javascript namespace object with its
own property, ajaxurl.
if not you must hardcode the url (not recommended) or you can use wp_localize_script()
PS: you can test the ajaxurl with console.log()
too
3) You must die();
[ not you, but the function =) ]
Like @iEmanuele said, you must die();
at the end of every function your ajaxcall
4) Ajax for logged in and logged out users
and another things is, you’re just enabling the ajax for people who are not logged in with wp_ajax_nopriv_ for be able to use the script with a logged in user you must add wp_ajax_
add_action( 'wp_ajax_twitchuser', 'twitchuser_ajax' );
add_action( 'wp_ajax_nopriv_twitchuser', 'twitchuser_ajax' );
function twitchuser_ajax() {
$twitchusername="MulloIV";
echo $twitchusername;
die();
}
Fixing:
the action wp_ajax_
and wp_ajax_nopriv_
must be followed by the action parameter in the ajax call in this case twitchuser