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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
$(document).ready(function(){ flight_app.get_flight('CX-400', function(flight){ console.log(flight); }); //console.log(flight_app.flight_id()); }); var flight_app = function(){ var flight_id = ''; function get_flight(flight_id, callback){ var app = this; $.ajax({ type: 'GET', url: fxml_url + 'FlightInfoEx', data: { 'ident': flight_id, 'howMany': 1, 'offset': 0 }, success : function(result) { //console.log(result); // display some textual details about the flight. var flight = result.FlightInfoExResult.flights[0]; //flight_id = flight.faFlightID; //console.log(flight); //console.log(get_std_time(flight.filed_departuretime)); //console.log(get_std_time(flight.estimatedarrivaltime)); if(typeof callback == 'function'){ callback.call(app, flight); } }, error: function(data, text) { alert('Failed to fetch flight: ' + data); }, dataType: 'jsonp', jsonp: 'jsonp_callback', xhrFields: { withCredentials: true } }); } function get_std_time(t){ var utcSeconds = t; var d = new Date(0); // The 0 there is the key, which sets the date to the epoch d.setUTCSeconds(utcSeconds); return d; } function get_flight_id(){ return flight_id; } return { get_flight: get_flight } }(); |
Reference: