I have this javascript function code to get the values from StationInfoGenerator.php.But when I want to get the values for passengers (suchs as from, to, arrivalTime,waitingTime), I couldn't put that values to the corresponding div tags in the html page.
function sta_callStation() {
$('#noOfPassengers, #infoOfPassengers, #distType,#distParams').empty();
$.getJSON('StationInfoGenerator.php', function (station) {
$.each(station, function (sta_key, sta_value) {
if (sta_key == "numberOfPassengers") {
$('#noOfPassengers').append("<strong>Number Of Passengers:
</strong>" + sta_value);
}
if (sta_key == "passengers") {
$('#infoOfPassengers').append("<strong>Passengers Information:</strong>" + '<br/>');
$.each(sta_key.passengers.parameters, function (i, parameters) {
$.each(parameters, function (par_key, par_value) {
$('#infoOfPassengers').append(par_key + ': ' + par_value + ' ' + '<br/>');
});
});
}
if (sta_key == "distType") {
$('#distType').append("<strong>Dağılım Tipi:</strong>" + sta_value);
}
});
});
}
Here is the html code part.In this part when I choose some station I must get the number of passengers ,passengers information, distribution type and params.For now I can get the numberOfPassengers from php.In php, all values are produced randomly.
<select name="selectStation" class="span12" onchange="sta_callStation();">
<option value="noStation">Bir istasyon seçiniz.</option>
<option value="station1">Station 1</option>
<option value="station2">Station 2</option>
<option value="station3">Station 3</option>
<option value="station4">Station 4</option>
<option value="station5">Station 5</option>
</select>
<div id="noOfPassengers"><strong>Number Of Passengers:</strong></div>
<p><i class="icon-user"></i> <i class="icon-user"></i> <i class="icon-user">
</i></p>
<div id="infoOfPassengers"></div>
<div id="distType"></div>
<div id="distParams"></div>
Php jsonSerialize part:
public function jsonSerialize()
{
$data = array();
$data['from'] = $this->from;
$data['to'] = $this->to;
$data['arrivalTime'] = $this->arrivalTime;
$data['waitingTime'] = $this->waitingTime;
return $data;
}
The output in the web page:
Number Of Passengers:5
Passengers Information:
How can I show the passengers info? Thanks.