我是 PHP 和 Javascript/Ajax 的新手,所以请多多包涵。
我需要做的就是从 Ajax 中获取一个变量并将其设置为 php 中的变量。我正在尝试使用超级全球性来做到这一点,GET
但有些事情是不对的。我不想通过提交表单来做到这一点。
这是我的 JS:
function myFunction(){
var hora= document.getElementById("hora").value;
$.ajax({
type : 'GET',
url : 'reservation.php',
data : {hora: hora},
success : function(data) {
console.log(hora);//This is because I was curious as to
// what the console would say. I found
// that this sets the super global if I
// change the url to something else that
// doesn't exist. Console would say
// -GET http://localhost/bus/(somepage).php?hora=4
// 404 (Not Found)-
alert(hora);
}
})
}
这是我的PHP:
Hora:
<select name="hora" id="hora" onchange="myFunction()">
<?php
$query = "SELECT * FROM vans";
$horas_result = mysql_query($query);
while ($horas = mysql_fetch_array($horas_result)) {
echo "<option value=\"{$horas["van_id"]}\">{$horas["time"]}</option>";
}
?>
</select>
Asientos Disponibles:
<?php echo $_GET["hora"]; ?>
//Right now I only want to echo this variable..
如您所见,现在我只想回显这个变量,稍后我将使用它来编写查询。