I have one clas and one .php file,
FIRST ONE, functions.php It's a .php file where it's my method that I am calling in the other class.
//PHP
add_action('wp_ajax_getJSONCurrencies', 'getJSONCurrencies');
add_action('wp_ajax_nopriv_getJSONCurrencies', 'getJSONCurrencies');
function getJSONCurrencies () {
$endpoint = $_POST['endp'];
$access_key = $_POST['access'];
$currencies = $_POST['curren'];
$source = $_POST['sour'];
$format = 1;
// Initialize CURL:
$ch = curl_init('https://apilayer.net/api/'.$endpoint.'?access_key='.$access_key.'¤cies='.$currencies.'&source='.$source.'&format='.$format.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Store the data:
$json = curl_exec($ch);
curl_close($ch);
// Decode JSON response:
echo json_decode($json, true);
}
And my second Class, custom-wc-widget...php where I call my first class function.
jQuery( document.body ).bind( \'bejob_price_slider_create bejob_price_slider_slide\', function( event, min, max ) {
var simMoneda = jQuery(\'.woocommerce-currency-switcher-form > select option:selected\').text();
var simbolo = simMoneda.split(",");
simMoneda = simbolo[1].trim();
var endpoint = \'live\';
var access_key = \'0a85b3479a1a24ceaba1d04f030e7028\';
var currencies = \'USD,ARS,CLP,PEN,COP,MXN,PAB\';
var source = \'EUR\';
jQuery.ajax({
type:\'POST\',
url: \'ajaxurl\',
//url: \'https://apilayer.net/api/\' + endpoint +\'?access_key=\' + access_key + \'¤cies=\' + currencies + \'&source=\' + source + \'&format=\' + 1,
data: {
endp: endpoint,
access: access_key,
curren: currencies,
sour: source,
action: \'getJSONCurrencies\'
},
dataType: "json",
success: function(data) {
debugger;
console.log(data);
}
});
if ( min == 0) {
jQuery( \'.bejob_price_slider_amount span.from\' ).html( "Gratis");
} else {
jQuery( \'.bejob_price_slider_amount span.from\' ).html( min + simMoneda );
}
jQuery( \'.bejob_price_slider_amount span.to\' ).html( max + simMoneda );
jQuery( document.body ).trigger( \'price_slider_updated\', [ min, max ] );
});
This second class has \' symbols because it's inside a echo php, my idea is to send the data in the ajax statement to my function getJSONCurrencies and then at the success function from the ajax method receive the JSON object I am going to use on my web page.
The problem is when I run the debugger it never enters in my Ajax Method and I dont know why it isn't entering there.