I'm sending the x jQuery variable to php file.
This is my jQuery with the ajax:
jQuery(document).ready(function($) {
var x = jQuery('#sbering option:selected').val();
jQuery('#optionvalue').html(x);
jQuery.ajax({
url: frontEndAjax.ajaxurl,
data: {
'action':'my_ajax_function',
'id' : x
},
success:function(data) {
console.log(data);
},
});
});
This is the function where I'm sending the x variable:
function my_ajax_function() {
if(isset($_REQUEST['id'])) {
$aux = $_REQUEST['id'];
echo "ID: " . $aux;
}
var_dump($aux);
...
instead of printing both $aux and var_dump($aux) on screen they're only visible in the console and $aux in php is Null.
What am I doing wrong?
$_REQUEST['id']to$_GET['id']?ID: ...in your console, in case you want to see output on screen try accessing directly theajaxurland add to it the proper query parameters since you useGET. In your case this would be?action=my_ajax_func&id=5var_dumpinside the if and update your question with the result ;)