Admin Ajax is returning 0

I am relatively new to jQuery and AJAX in particular. I have a small issue with the return value always being 0, though I think this is actually the success message and it’s not returning anything.

I have scoured the Google-verse and I have the die() function on the PHP callback and I believe the add_actions are correct.

I am working on a local host, though I doubt that affects it and this is all in the admin, not front end. I also checked that the js is enqueued and localised.

I get a 200 OK message in the chrome developer area.

I also tested out the basic AJAX from http://codex.wordpress.org/AJAX_in_Plugins and it also returned 0, which makes me wonder if it is something other than the code outlined below.

Right now I am just trying to make it send something back to the jQuery. Any help would be appreciated.

The jQuery

jQuery(document).ready(function(){
    jQuery('.cl_link_buttons').val('id').click(function() {

            var currentid = jQuery(this).attr('id');

            //alert(currentid);
            console.log(currentid);

            jQuery.ajax ( data = {
                action: 'cleanlinks_ajax_get_post_data',
                url: ajaxurl,
                type: 'POST',
                dataType: 'text',
                "currentid" : currentid

            });

            jQuery.post(ajaxurl, data, function(response) {

                var dataz = response;
                alert( dataz );
                console.log (dataz); //show json in console


            });

            return false;

    }); //end click event
}); //end doc ready

The PHP

add_action("wp_ajax_cleanlinks_ajax_get_post_data", "cleanlinks_ajax_get_post_data");
add_action("wp_ajax_nopriv_cleanlinks_ajax_get_post_data", "cleanlinks_ajax_get_post_data");

function cleanlinks_ajax_get_post_data() {

$from_ajax =  $_POST['currentid'];

echo "do" . $from_ajax . "something";

die();


}

1
15

A 0 response means either that the action is not set (in the ajax data) or that the action’s callback function cannot be found.

Leave a Comment