-1

I have this api

https://api.flightstats.com/flex/flightstatus/rest/v2/xml/route/status/LHR/MAN/arr/2013/08/06?appId=ID&appKey=KEY&hourOfDay=0&numHours=24&utc=false&maxFlights=5

It returns a response in an xml format. This is a sample response.

<flightStatus>
<flightId>305133622</flightId>
<carrierFsCode>BA</carrierFsCode>
<flightNumber>1382</flightNumber>
<departureAirportFsCode>LHR</departureAirportFsCode>
<arrivalAirportFsCode>MAN</arrivalAirportFsCode>
<departureDate>
<dateLocal>2013-08-06T06:30:00.000</dateLocal>
<dateUtc>2013-08-06T05:30:00.000Z</dateUtc>
</departureDate>

I want to display the flight number and arrival time in html. How to go about that?

The code snippet is from the response; its not from an xml file that i have.

This is what i have tried.

<script>
function getResponse()
        {


            $.ajax({
            type: 'POST',
            url: 'https://api.flightstats.com/flex/flightstatus/rest/v2/xml/route/status/LHR/MAN/arr/2013/08/06?appId=ID&appKey=KEY&hourOfDay=0&numHours=24&utc=false&maxFlights=5',
            data: {},
            dataType: 'xml',
            success: function(data) 
            { $("display").html(data); },
            error: function() { alert('something bad happened'); }
            });

        }    
</script>
4

2 回答 2

2
$.ajax({
                type: "GET",               
               url: URL,               
                dataType: "jsonp",
               error: function (response) {           
                        alert('Error: There was a problem processing your request, please refresh the browser and try again');
                },
                success: function (response) {
            console.log(response);
               }
        });

I worked on it and jsonp seems to be the way to go!!

Thanks for the help @Quentin @Akki619

于 2013-08-07T16:17:50.130 回答
-3

There are lot's of solution out there. Please do your research before posting any question...For now here is a good example from w3 schools to get you started.

w3schools Example

Something like this.....

var URL =" https://api.flightstats.com/flex/flightstatus/rest/v2/xml/route/status/LHR/MAN/arr/2013/08/06?appId=ID&appKey=KEY&hourOfDay=0&numHours=24&utc=false&maxFlights=5";

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET",URL,false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 
于 2013-08-07T05:57:51.947 回答