0

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.

Edited by ravi142: output add

2
Contributors
1
Reply
12
Views
2 Years
Discussion Span
Last Post by irfanmodan
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.