I want to post a value from a dropdown list to a php file with JSON_encode using $_POST Ajax.
I tried this script :
jQuery(document).ready(function($) {
$('select.pam').change(function(){
$.ajax({
type: 'POST',
url: '/charta.php',
dataType:'json',
data: { id_espece:$('select.pam').val()},
success: function(output) {
alert(output);
},
});
});
});
and this is where I want to post it :
<?php $id = $_POST['id_espece'];
$cars = abv($id);
print json_encode($cars);
But I get :
Notice: Undefined variable: cars in C:\wamp64\www\charta.php on line 39
to be sure that the JSON file is correct I replaced $_POST['id_espece']
with a default value and it works , but whene I attached it to the select box I get the error .