Я хочу преобразовать переменную javascript в переменную php, чтобы использовать ее в SQL-запросе, но она не работает.
html-код:
<select id = "dep_ID" name = "dep_ID" onchange="myFunction()">
код JavaScript в том же файле:
<script>
function myFunction(){
var xo = document.getElementById("dep_ID").value;
document.getElementById("demo").innerHTML = "You selected: " + xo;
$.ajax({
url: 'insert.php',
data: {duration: xo},
type: 'POST',
success: function(data) {
alert(data);
document.getElementById("demo").innerHTML = "You selected: " + <?php echo @$duration;?>;
}
});
}
</script>
код insert.php:
<?php
$duration = $_POST['xo'];
return $duration ;
?>
Я ожидаю вывод переменной dep_ID,но я ничего не получаю.