Admin-ajax returns a 0
-
I am trying to write a simple ajax call that grabs the value of an input on blur and returns it. The ajax call is in a folder called ‘scripts’ in my themes directory and the function is in functions.php. My code is as follows:
$(document).ready(function(){ $("#trading_card_amount").blur(function(){ var cardAmt = $(this).val(); $.ajax({ type: 'POST', url: '/../../../../wp-admin/admin-ajax.php', data: { action: 'populate_qualified_cards', cardAmt: cardAmt, }, success: function(data){ console.log(data); }, error: function(){ console.log('error'); } }); });and in functions.php i have:
function populate_qualified_cards(){ $amt = $_POST['cardAmt']; echo $amt; die(); } add_action( 'wp_ajax_nopriv_populate_qualified_cards', 'populate_qualified_cards' ); add_action( 'wp_ajax_populate_qualified_cards', 'populate_qualified_cards' );Any ideas why I only get a zero in the console log? Help please!!!!!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Admin-ajax returns a 0’ is closed to new replies.