I'm trying to "POST" data from my Form through ajax to a mysql database. This code is hooked to the "after_setup_theme" action:
add_action("wp_ajax_ajax_anmeldung", "ajax_anmeldung");
add_action("wp_ajax_nopriv_ajax_anmeldung", "ajax_anmeldung");
function ajax_anmeldung() {
echo "<script>
alert('hey');
</script>";
die();
}
And this is the JS code that calls it:
$('#teilnahme_form').submit(function(e){
e.preventDefault();
var name = document.getElementById("name").value;
jQuery.ajax({
type:"POST",
url: window.ajaxurl,
data: {
action: "ajax_anmeldung",
name : name
},
success:function(data){
alert(data);
}
});
});
When I run this I get returned a "0", nothing more.
When I tried: http://my-domain.com/wp-admin/admin-ajax.php?action=ajax_anmeldung I also get a "0".
I read all the others post on here surrounding this topic, but nothing seemed to help me, or I overlooked something really important.
Cheers