AJAX request returns 0
-
I’m trying to get my AJAX request working and regardless of what I try, it always returns 0 and I’ve looked everywhere to find a solution and nothing works at all. This is the code I have right now.
JavaScript:
jQuery(document).ready(function($) { $('.button').on('click', function(e) { e.preventDefault(); $.ajax({ data: { action: 'my_action', data: 'test' }, type: 'post', url: PLUGIN.ajax_url, success: function(response) { console.log(response); } }); }); });
PHP:
function ajax_callback() { echo "test"; exit(); } add_action('wp_ajax_noprov_my_action', 'ajax_callback'); add_action('wp_ajax_my_action', 'ajax_callback');
What am I doing wrong here? The script is included properly and is clearly running. I’m expecting to just print “test” into the console just to know it works but it’s not even doing that.
Any ideas?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘AJAX request returns 0’ is closed to new replies.