我是 html 的新手并试图在数据库之间建立关系。我想用数据库填充框
我有一个类似的代码
<div class="content" data-role="content" id="content" >
<div id="car">
<select name="selectCar" class="span12" id="Options" >
<option value="-1">Bir istasyon seçiniz.</option>
<option value="1">Mimarlık</option>
<option value="2">Yurtlar</option>
<option value="3">Bilgisayar Mühendisliği</option>
<option value="4">Kimya Mühendisliği</option>
<option value="5">Rektörlük</option>
</select>
</div>
<div id="cinfo"></div>
<button onclick="javascript:callCarInfo.call(this,document.getElementById('Options').value);">Call Podcar</button>
</div>
这里
<option value="1">Mimarlık</option>
<option value="2">Yurtlar</option>
<option value="3">Bilgisayar Mühendisliği</option>
<option value="4">Kimya Mühendisliği</option>
<option value="5">Rektörlük</option>
我想用数据库填充这些值和站点名称
我也有一个站功能是
function getStationList()
{
$db = new DBManager();
$mysqli = $db->db_connect();
$query = "SELECT stationId FROM Station";
$stmt = $mysqli->prepare($query);
$stmt->execute();
$result = $stmt->get_result();
$list = array();
while($row = $result->fetch_assoc())
{
$list[] = $row['stationId'];
}
return json_encode($list);
}
我尝试使用 ajax 功能,但我做不到
$.ajax({
url:'Stations.php',
type:'POST',
data: 'q=' + str,
dataType: 'json',
success: function( json ) {
$.each(json, function(i, value) {
$('#myselect').append($('<option>').text(value).attr('value', value));
});
}
});