我收到一个类型错误:javascript 代码上的 e 未定义。我正在尝试使用 jquery 填充从 mysql 服务器发送的数据的下拉列表。
这是javascript代码
$(document).ready(function(){// This script uses jquery and ajax it is used to set the values in
$("#day").change(function(){// the time field whenever a day is selected.
var day=$("#day").val();
var doctor=$("#doctor").val();
$.ajax({
type:"post",
url:"time.php",
data:"day="+day+"&doctor="+doctor,
dataType : 'json',
success:function(data){
var option = '';
$.each(data.d, function(index, value) {
console.log(data.d);
option += '<option>' + value.arr + '</option>';
});
$('#timing').html(option);
}
});
});
});
这是从 mysql 数据库中获取数据的 php 脚本
$doctor = $_POST['doctor'];
$day = $_POST['day'];
$query="SELECT * FROM schedule WHERE doctor='$doctor' AND day='$day'";
$arr = array();
$result = mysqli_query($con, $query);
$i = 0;
//Initialize the variable which passes over the array key values
$row = mysqli_fetch_assoc($result); //Fetches an associative array of the row
$index = array_keys($row); // Fetches an array of keys for the row.
while($row[$index[$i]] != NULL)
{
if($row[$index[$i]] == 1) {
//$res = $index[$i];
//echo json_encode($res);
array_push($arr, $index[$res]);
}
$i++;
}