如何解决Rest API中的此数组错误

时间:2018-09-05 05:29:45

标签: php ajax laravel api

我正在创建票务预订系统。因此,在此系统中,我使用API​​来请求和获取(响应)数据。但是,当我从API获得响应时,它包含数组数组。

{
  "OTA_AirLowFareSearchRS": {
    "PricedItinCount": 25,
    "BrandedOneWayItinCount": 0,
    "SimpleOneWayItinCount": 0,
    "DepartedItinCount": 0,
    "SoldOutItinCount": 0,
    "AvailableItinCount": 0,
    "Version": "4.2.0",
    "Success": {},
    "Warnings": {
      "Warning": [
        {
          "Type": "WORKERTHREAD",
          "ShortText": "2878556866627349184",
          "Code": "TRANSACTIONID",
          "MessageClass": "I",
          "content": ""
        },
        {
          "Type": "SERVER",
          "ShortText": "27041",
          "Code": "TTFHLC703",
          "MessageClass": "I",
          "content": ""
        },
        {
          "Type": "DRE",
          "ShortText": "13291",
          "Code": "RULEID",
          "MessageClass": "I",
          "content": ""
        },
        {
          "Type": "DEFAULT",
          "ShortText": "25238",
          "Code": "RULEID",
          "MessageClass": "I",
          "content": ""
        }
      ]
    },
    "PricedItineraries": {
      "PricedItinerary": [
        {
          "SequenceNumber": 1,
          "AirItinerary": {
            "DirectionInd": "Return",
            "OriginDestinationOptions": {
              "OriginDestinationOption": [
                {
                  "ElapsedTime": 1030,
                  "FlightSegment": [
                    {
                      "DepartureDateTime": "2018-11-10T07:10:00",
                      "ArrivalDateTime": "2018-11-10T08:38:00",
                      "StopQuantity": 0,
                      "FlightNumber": "2912",
                      "ResBookDesigCode": "V",
                      "ElapsedTime": 208,
                      "DepartureAirport": {
                        "LocationCode": "DFW",
                        "TerminalID": "E",
                        "content": ""
                      },
                      "ArrivalAirport": {
                        "LocationCode": "LAX",
                        "TerminalID": "2",
                        "content": ""
                      },
                      "OperatingAirline": {
                        "Code": "DL",
                        "FlightNumber": "2912",
                        "content": ""
                      },
                      "Equipment": [
                        {
                          "AirEquipType": "319",
                          "content": ""
                        }
                      ],
                      "MarketingAirline": {
                        "Code": "DL",
                        "content": ""
                      },
                      "MarriageGrp": "O",
                      "DepartureTimeZone": {
                        "GMTOffset": -6
                      },
                      "ArrivalTimeZone": {
                        "GMTOffset": -8
                      },
                      "OnTimePerformance": {
                        "Level": "7"
                      },
                      "TPA_Extensions": {
                        "eTicket": {
                          "Ind": true
                        },
                        "Mileage": {
                          "Amount": 1235
                        }
                      }
                    }
                    ]
                    }

现在,我想在视图页面中读取并显示这些值。我的意思是我想获取并显示PricedItinCount,DepartureDateTime和ArrivalAirport-> LocationCode。然后,我尝试使用Jquery和Ajax执行以下步骤。我了解了所有细节

  

Console.log(data);

但是,没有任何东西进入视图页面。如何获取视图页面的值?

查看页面。

<form class="form-horizontal" method="POST" action="#" enctype="multipart/form-data" id="signupForm">

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Origin City : <input type="text" class="form-control" name="origin" value="CMB" id="origin"> <br>
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Destination City : <input type="text" class="form-control" name="destination" value="DUB"
                                              id="destination"> <br>
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->

                    <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                        Adults : <select name="adults" class="form-control" id="adults">
                            <option value="1">1</option>
                        </select> <br>
                    </div>

                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Departure Date : <input class="form-control" name="departureDate" id="departureDate">
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Return Date : <input class="form-control" name="returnDate" id="returnDate">
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Travel Class : <select name="travelClass" class="form-control" id="travelClass">
                            <option value="ECONOMY">ECONOMY</option>
                            <option value="BUSINESS">BUSINESS</option>
                    </select> <br>
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Access Token : <input type="text" class="form-control" name="bat" value="" id="bat">
                </div>

                <a href="#" id="ghsubmitbtn" class="btn btn-success">Search Flight Data</a>

                <p id="errorModal"></p> <br>

                <div id="ghapidata" class="clearfix"></div>

            </form>

            <h3>Tasks of the Developers</h3> <br>

            <div class="table-responsive">
                <table class="table table-striped table-bordered text-left" id="tblData">
                    <thead>
                    <tr class="info">
                        <td>PricedItinCount</td>
                        <td>Id</td>
                    </tr>

                    <tbody id="tblBody"></tbody>
                    </thead>
                </table>
            </div>

            <script type="text/javascript">
                $(document).ready(function () {

                    $('#ghsubmitbtn').on('click', function(e) {
                        var Target = 'Production';
                        var bat = 'T1RLAQJBqX+k4EiXWQziU3GvPPsN69ozuhBwOBhA97cFiyxKiyylxmA1AADAM6s/5sV+ZLOBPsYTHiPtad9ByBlsN91C4XxIhcT6kLibIww/Ezpv3CvJCwcp7xJZhU0oQLpu+8DVQ3lcsgnUGkAeu4SvF7h4BJs5IMpkVgpuTOEX9jeGT2TljavgPtrqVG62xcX2ZPYEOKO20IPQqZE9isl9EQH1bgRVCba0FzQ7m6zbfPGpwf20KCWMCfO69IYTbx5krbLf3aIyp8Db+5GSXKOdqIp6s9aDP0RIrkmDhEYO3H8tYTIqj6rQPrjf';

                         var JSONObj = {
                         "OTA_AirLowFareSearchRQ": {
                             "Target": Target,
                               "POS": {
                                    "Source": [{
                                        "PseudoCityCode":"F9CE",
                                        "RequestorID": {
                                            "Type": "1",
                                          "ID": "1",
                                            "CompanyName": {

                                          }
                                     }
                                 }]
                                },
                                "OriginDestinationInformation": [{
                                  "RPH": "1",
                                   "DepartureDateTime": "2018-11-10T11:00:00",
                                   "OriginLocation": {
                                     "LocationCode": "DFW"
                                 },
                                    "DestinationLocation": {
                                        "LocationCode": "CDG"
                                 },
                                    "TPA_Extensions": {
                                     "SegmentType": {
                                            "Code": "O"
                                       }
                                 }
                             },
                                {
                                 "RPH": "2",
                                   "DepartureDateTime": "2018-11-11T11:00:00",
                                   "OriginLocation": {
                                     "LocationCode": "CDG"
                                 },
                                    "DestinationLocation": {
                                        "LocationCode": "DFW"
                                 },
                                    "TPA_Extensions": {
                                     "SegmentType": {
                                            "Code": "O"
                                       }
                                 }
                             }],
                               "TravelPreferences": {
                                  "ValidInterlineTicket": true,
                                   "CabinPref": [{
                                     "Cabin": "Y",
                                     "PreferLevel": "Preferred"
                                    }],
                                   "TPA_Extensions": {
                                     "TripType": {
                                           "Value": "Return"
                                     },
                                        "LongConnectTime": {
                                            "Min": 780,
                                         "Max": 1200,
                                            "Enable": true
                                      },
                                        "ExcludeCallDirectCarriers": {
                                          "Enabled": true
                                     }
                                 }
                             },
                                "TravelerInfoSummary": {
                                    "SeatsRequested": [1],
                                  "AirTravelerAvail": [{
                                      "PassengerTypeQuantity": [{
                                         "Code": "ADT",
                                            "Quantity": 1
                                       }]
                                    }]
                                },
                                "TPA_Extensions": {
                                 "IntelliSellTransaction": {
                                     "RequestType": {
                                            "Name": "50ITINS"
                                     }
                                 }
                             }
                         }
                        };

                        var data = JSON.stringify(JSONObj);

                        $.ajax({
                            url: 'https://api-crt.cert.havail.sabre.com/v4.2.0/shop/flights?mode=live&limit=50&offset=1',
                            method: 'POST',
                            contentType:"application/json; charset=utf-8",
                            data: data,
                            headers: {"Authorization": 'Bearer ' + bat},

                            success: function (data) {

                                console.log(data);

                                $.each(data, function (index, value) {

                                    var BookBtn = '<input type="submit" value="Book" name="book" class="btn btn-primary">';

                                    for (var v = 0; v <= 999; v++) {
                                    var row = $('<tr><td>' + value[0].PricedItinCount + '</td><td>'
                                        + value[v].Version + '</td><td>'
                                        + value[v].Warnings[0].Warning[0].Type + '</td><td>'
                                        + BookBtn + '</td></tr>');
                                    $('#tblData').append(row);}
                                });


                            },

                        });
                    });
                });
            </script>

0 个答案:

没有答案