I have a problem with AJAX returning 0 always!
I have done everything by the book and can’t figure out what is wrong? Please help!!
Here is my Ajax call:
//Pass data through AJAX
var amountToConvert = price;
jQuery.ajax({
type:"POST",
url: "../../wp-admin/admin-ajax.php", // our PHP handler file
action: "ajaxConversion",
data: {
amount: amountToConvert
},
success:function(data){
alert(data);
},
error: function(errorThrown){
alert(errorThrown);
}
});
return false;
And the function in functions.php is:
function ajaxConversion(){
$amount = mysql_real_escape_string($_POST['amount']);
echo $amount;
die();
};
add_action('wp_ajax_nopriv_ajaxConversion', 'ajaxConversion');
add_action('wp_ajax_ajaxConversion', 'ajaxConversion');
Could you place the action (ajaxConversion) in your Data and check?
jQuery.ajax({
type:"POST",
url: ajaxurl,
data: {
action: "ajaxConversion",
amount: amountToConvert
},
success:function(data){
alert(data);
},
error: function(errorThrown){
alert(errorThrown);
}
});