Difficulty to use AirlineFlightInfo in javascript

Hi

I am using the code below to get the tailnumber of an aircraft

function flightData(fa_FlightID) {
//var result;
$.ajax({
type: ‘GET’,
url: fxml_url + ‘AirlineFlightInfo’,
data: { ‘faFlightID’: ‘AUA537-1471584553-airline-0118:0’},
success: function(mydata) {
alert(mydata.TailNumber);
}
});
return mydata; ------> this is failing, I do not pass inside “success”, any idea why???
}

function flightDataTailNumber(fa_FlightID) {
var flight=flightData(fa_FlightID);
var result=flightData.TailNumber;
return (result);
}

then I call the flightDataTailNumber(fa_FlightID) later in my code…

However, as s you can see, I hard-coded data: { ‘faFlightID’: ‘AUA537-1471584553-airline-0118:0’}, when it will work, I will replace it by data: { ‘faFlightID’: fa_FlightID},

If I try the URL
flightxml.flightaware.com/json/F … ine-0118:0

I get

{“AirlineFlightInfoResult”:{“faFlightID”:“AUA537-1471584553-airline-0118:0”,“ident”:“AUA537”,“codeshares”:“SWR537”],“tailnumber”:“OELGL”,“meal_service”:“”,“gate_orig”:“”,“gate_dest”:“”,“terminal_orig”:“2”,“terminal_dest”:“”,“bag_claim”:“”,“seats_cabin_first”:0,“seats_cabin_business”:0,“seats_cabin_coach”:0}}

Are you sure that your request using the fa_FlightID variable is actually being generated with the desired faFlightID value? It sounds like you may simply have a variable passing problem, perhaps causing the literal text “fa_FlightID” to be sent instead of the contents of that variable?

You can try using the developer tools functionality in your web-browser to see the contents of the actual failing GET request that is being generated to verify that.

Hi,

Thanks for your answer. Actually I try first to debug with an harcoded value passed to the query :
‘faFlightID’: ‘AUA537-1471584553-airline-0118:0’ but my problem might also come from the way I play with the ajax call.

Thibaut

Have you already tried including these arguments to the $.ajax() call?



        dataType: 'jsonp',
        jsonp: 'jsonp_callback',
        xhrFields: { withCredentials: true }


I assume that your fxml_url has your username and API key in the URL?

Be aware that Internet Explorer (maybe MS Edge also?) may not be able to invoke this AJAX method properly due to its differences in security implementation.

Yes, it does and it works very well with other queries, actually the URL I use directly with the browser is what I capture in inpect mode with Firefox.

Have you actually tried to use any other other FlightXML method through your javascript successfully? I suspect there is nothing specifically wrong with AirlineFlightInfo, but your problem extends to all methods.

What error code is the server responding with for your requests?

Please also keep in mind that we do not recommend that direct Javascript invocation of FlightXML be done on internet-accessible applications, and that this technique be limited to internal/intranet-hosted applications.