Support » Plugins » AJAX returning 0

  • I am trying to do a basic ajax function but all I can get back is a 0. Code is as follows:

    In my main script.js file I have:

    function populateCardAmount(){
        var cardAmt = $("#trading_card_amount").val();
                type: 'POST',
                url: '/wp-admin/admin-ajax.php',
                data: {
                    action: 'populate_qualified_cards',
                    cardAmt: cardAmt,
                success: function(data){
                error: function(){

    And in functions.php I have:

    function populate_qualified_cards(){
        $amt = $_POST['cardAmt'];
    add_action( 'wp_ajax_nopriv_populate_qualified_cards', 'populate_qualified_cards' );
    add_action( 'wp_ajax_populate_qualified_cards', 'populate_qualified_cards' );

    Help Please!!! Thank you!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Also, the js function is being called on pageload:



    Did you ever find anything out on this? I’m in the same predicament.



    Make sure ajax action matches first param of add_action in functions.php. And second param matches function name, but call both params different names. And I had to direct back an additional folder to admin-ajax



    Hey.. thanks for posting back so quick!!

    I actually found that you must add the add_action bit to the top level of the plugin.

    I had it nested inside my admin_menu hook, which didn’t work. Moving it up one level to the construct, solved the issue.

    Man… I LOVE AJAX!!

    Again, thanks for the help!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘AJAX returning 0’ is closed to new replies.