我正在使用Flightstats api,我想等待JSONP的回调,例如从特定日期起只接收“AA”航班。 因为Flightstats api只允许一次请求一小时,我必须同时发出24个请求。 谢谢你的帮助。
<script type="text/javascript">
var scheduledFlightsArray = new Array();
for (var i = 0; i < 24; i++)
{
var src = "https://api.flightstats.com/flex/schedules/rest/v1/jsonp/from/KSFO/departing/2014/12/5/" + i + "?appId=*****&appKey=*****";
var script = document.createElement('script');
script.src = src;
document.body.appendChild(script);
}
function callback(data)
{
var scheduledFlights = data.scheduledFlights;
for (var i = 0; i < scheduledFlights.length; i++)
{
if (scheduledFlights[i].carrierFsCode == "AA" && !scheduledFlights[i].operator)
{
scheduledFlightsArray.push(scheduledFlights[i]);
}
}
}
for (var i = 0; i < scheduledFlightsArray.length; i++)
{
console.log(scheduledFlightsArray[i].carrierFsCode + scheduledFlightsArray[i].flightNumber);
}
</script>