WordPress AJAX return 0 – My case

My problem is the same as in other cases, but my code is fine, I compared with another and followed all the instructions and good practices, but it does not work. Here my code:

jQuery(“#genera-pdf”).click(function(e){
e.preventDefault();
var price1 = jQuery(‘input[type=text][id=price1]’).val();
var price2 = jQuery(‘input[type=text][id=price2]’).val();

jQuery.ajax({
url : ‘/wp-admin/admin-ajax.php’,
type: ‘POST’,
data: {action: ‘pdfAction’, a: price1, b: price2}),
success: function(data){
alert(data);
},
error: function(errorThrown){
alert(errorThrown);
}
});
});

And my function is:

function pdfAction(){
$post = $_POST[‘pdfAction’];
echo “something”;

wp_die();

}
add_action(‘wp_ajax_pdfAction’,’pdfAction_callback’);
add_action(‘wp_ajax_nopriv_pdfAction’,’pdfAction_callback’);

Any idea that is happening?

Read more here:: WordPress AJAX return 0 – My case

Leave a Reply

Your email address will not be published. Required fields are marked *