-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (33 loc) · 1.27 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
document.getElementById('flight-search-form').addEventListener('submit', function(event) {
event.preventDefault();
const origin = document.getElementById('origin').value;
const destination = document.getElementById('destination').value;
const departureDate = document.getElementById('departure-date').value;
fetch(`https://api.amadeus.com/v1/shopping/flight-offers?origin=${origin}&destination=${destination}&departureDate=${departureDate}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer ebGRBXoTiv6Xqc9syywti8ohD0IQzI4O'
}
})
.then(response => response.json())
.then(data => {
displayResults(data);
})
.catch(error => {
console.error('Error:', error);
});
});
function displayResults(data) {
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '';
data.data.forEach(flight => {
const flightInfo = document.createElement('div');
flightInfo.innerHTML = `
<p>Airline: ${flight.airline}</p>
<p>Flight Number: ${flight.flight_number}</p>
<p>Departure Time: ${flight.departure_time}</p>
<p>Arrival Time: ${flight.arrival_time}</p>
`;
resultsDiv.appendChild(flightInfo);
});
}