-1

データベースからステーション リストを取得し、オプション リストに入力する方法を教えてください。1 つのボタンとオプション リストを含む html ファイルがあります。データベースから取得して、これらのオプションにステーションのリストを入力したいと思います。このような私のajax関数。

$(document).ready(function() {

var q = $("#q").val();

$.ajax({

url:'Stations.php',
type:'POST',
data: 'q=' + str, 
dataType: 'json',
success: function( json ) {
    $.each(json, function(i, value) {
        $('#selectSt')
              .append($('<option></option>', {text:value})
              .attr('value', text));
        });
    }
  });
});

私の駅.php

    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);
    }

私のdivクラス。

<div class="content" data-role="content" id="content" >
     <div id="car">
        <select name="selectSt" class="span12" id="selectSt" > 
        <option></option>
        <option></option>     /*I want to fill these gaps.
        <option></option>
        </select> 


     </div>
     <div id="cinfo"></div>
    <button onclick="javascript:callCarInfo.call(this,document.getElementById('selectSt').value);">Call     Podcar</button>
 </div>

何が欠けているか、または何をすべきか教えてください。

4

1 に答える 1