Hello.

I am working on wordpress plugin.php file Add one sub menu and working on but when i call ajax function but its not given proper output.

<script>
jQuery(document).ready(function() {
jQuery(".downloadpdf").click(function () {

        var goat_id = jQuery(this).attr('id');  //Alert got id e.g 218

        jQuery.ajax({
            type: "POST",
            url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
            async:false,
            data: ({
                action: 'add_goat_details',
                goat_id: goat_id 
            }),
            success: function(data) {
            }
        });

    });
});
</script>

add_action('wp_ajax_nopriv_add_goat_details', 'add_goat_details');
add_action('wp_ajax_add_goat_details', 'add_goat_details');

function add_goat_details(){

    echo $_POST['goat_id']."-Output";           //Given me '0'as output.
}

OUTPUT: Goat id given as '0' output.

suggest me what i actual mistakes.

Thank you.

use exit(0); after echo $_POST['goat_id']."-Output";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.