0

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.

4

2 回答 2

0
function sta_callStation()
  {
    var distName;
    $('#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(station.passengers, function(i,passenger) {

           $.each(passenger, function(par_key, par_value) {


              $('#infoOfPassengers').append(par_key+': '+par_value+'  '+'<br/>');
         });
           $('#infoOfPassengers').append('<hr />');
        });

        }

        if(sta_key=="distType") 
        {

          if(sta_value=="1"){
            distName="Uniform";
          }
          if(sta_value=="2"){
            distName="Normal";
          }
          if(sta_value=="3"){
            distName="Üstel";
          }
          if(sta_value=="4"){
            distName="Geometric";
          }

        $('#distType').append("<strong>Distribution Type:</strong>"+sta_value+"<br/>"+"<strong>Distribution Name:</strong>"+distName);


      }
        if(sta_key=="distParams") 
        {

         $('#distParams').append("<strong>Distribution Parameters:</strong>"+'<br/>');



            $.each(station.distParams, function(params_key, params_value) {


              $('#distParams').append(params_key+': '+params_value+'  '+'<br/>');
              //$('#distParams').append('<hr />');
         });





        }
      });

  });
  }
于 2013-03-30T11:35:58.030 回答
0
public function jsonSerialize()
{
    $data = array();
    $data['from'] = $this->from;
    $data['to'] = $this->to;
    $data['arrivalTime'] = $this->arrivalTime;
    $data['waitingTime'] = $this->waitingTime;
    return json_encode($data);
}
于 2013-03-30T10:04:55.717 回答