So I started using Amadeus REST API , and have been using AJAX call to get data , but now I have to represent that data in certain format , and I am not sure how to loop or show data
function showdataforflights(data) {
jQuery.each(data, function(index, item) {
console.log(item.itineraries.outbound.flights.departs_at);
console.log('wadasd');
});
};
$("#main_form").on('submit', (function(e) {
e.preventDefault();
$('.loader').show();
$("html, body").scrollTop(0);
$.ajax({
url: "./search/amadeus.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData($('form')[0]), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
processData: false,
contentType: false,
success: function(data) // A function to be called if request succeeds
{
$('.loader').hide();
$('#lala').text(JSON.stringify(data.results));
showdataforflights(data.results);
}
});
}));
This is where I'm stuck. I don't know how to loop through the data so that I can show data in particular HTML format .
JSON:
{
"currency": "USD",
"results": [
{
"itineraries": [
{
"outbound": {
"flights": [
{
"departs_at": "2017-12-30T13:00",
"arrives_at": "2017-12-30T15:10",
"origin": {
"airport": "DEL",
"terminal": "3"
},
"destination": {
"airport": "BOM",
"terminal": "2"
},
"marketing_airline": "AI",
"operating_airline": "AI",
"flight_number": "863",
"aircraft": "744",
"booking_info": {
"travel_class": "ECONOMY",
"booking_code": "S",
"seats_remaining": "2"
}
}
]
}
}
],
"fare": {
"total_price": "73.39",
"price_per_adult": {
"total_fare": "73.39",
"tax": "8.39"
},
"restrictions": {
"refundable": true,
"change_penalties": true
}
}
},
{
"itineraries": [
{
"outbound": {
"flights": [
{
"departs_at": "2017-12-30T04:00",
"arrives_at": "2017-12-30T06:15",
"origin": {
"airport": "DEL",
"terminal": "3"
},
"destination": {
"airport": "BOM",
"terminal": "2"
},
"marketing_airline": "AI",
"operating_airline": "AI",
"flight_number": "349",
"aircraft": "788",
"booking_info": {
"travel_class": "ECONOMY",
"booking_code": "U",
"seats_remaining": "9"
}
}
]
}
}
],
"fare": {
"total_price": "106.99",
"price_per_adult": {
"total_fare": "106.99",
"tax": "9.99"
},
"restrictions": {
"refundable": true,
"change_penalties": true
}
}
},
{
"itineraries": [
{
"outbound": {
"flights": [
{
"departs_at": "2017-12-30T08:00",
"arrives_at": "2017-12-30T10:10",
"origin": {
"airport": "DEL",
"terminal": "3"
},
"destination": {
"airport": "BOM",
"terminal": "2"
},
"marketing_airline": "9W",
"operating_airline": "9W",
"flight_number": "336",
"aircraft": "73H",
"booking_info": {
"travel_class": "ECONOMY",
"booking_code": "H",
"seats_remaining": "1"
}
}
]
}
}
],
"fare": {
"total_price": "116.35",
"price_per_adult": {
"total_fare": "116.35",
"tax": "45.35"
},
"restrictions": {
"refundable": true,
"change_penalties": true
}
}
},
{
"itineraries": [
{
"outbound": {
"flights": [
{
"departs_at": "2017-12-30T06:00",
"arrives_at": "2017-12-30T08:05",
"origin": {
"airport": "DEL",
"terminal": "3"
},
"destination": {
"airport": "BOM",
"terminal": "2"
},
"marketing_airline": "UK",
"operating_airline": "UK",
"flight_number": "975",
"aircraft": "320",
"booking_info": {
"travel_class": "PREMIUM_ECONOMY",
"booking_code": "U",
"seats_remaining": "9"
}
}
]
}
}
],
"fare": {
"total_price": "122.61",
"price_per_adult": {
"total_fare": "122.61",
"tax": "19.61"
},
"restrictions": {
"refundable": true,
"change_penalties": true
}
}
},
{
"itineraries": [
{
"outbound": {
"flights": [
{
"departs_at": "2017-12-30T20:05",
"arrives_at": "2017-12-30T22:05",
"origin": {
"airport": "DEL",
"terminal": "1D"
},
"destination": {
"airport": "BOM",
"terminal": "1"
},
"marketing_airline": "H1",
"operating_airline": "SG",
"flight_number": "9071",
"aircraft": "737",
"booking_info": {
"travel_class": "ECONOMY",
"booking_code": "L",
"seats_remaining": "2"
}
}
]
}
}
],
"fare": {
"total_price": "185.45",
"price_per_adult": {
"total_fare": "185.45",
"tax": "84.45"
},
"restrictions": {
"refundable": false,
"change_penalties": true
}
}
}
]
}