2

I'm trying to practice jquery with webservices and callign on of he open xml service from US Airports.

webservice url is http://services.faa.gov/airport/status/IAD?format=application/xml

and my Query code as below but when the page is loaded it shows an empty screen :( can someone guide me please. I searched online and couldnt' figure out.

<html>
<head>
    <script type="text/javascript" src="assets/jquery.js"></script>
    <title>Aviation</title>
    <script type="text/javascript">
        $(document).ready(function () {
        $.ajax({
        type: "GET",
        url: "http://services.faa.gov/airport/status/IAD?format=application/xml",
        dataType: "xml",
        success: xmlParser
        });
    });

    function xmlParser(xml) {

        $('#airport').fadeOut();
        $(xml).find("AirportStatus").each(function () {
        $("#details").append($(this).find("ICAO").text() + "</br>"+ $(this).find("State").text());
        //$(".book").fadeIn(1000);
        });
    }
    </script>
</head>
<body>
    <p id="airport">Loading...</p>
    <p id="details"></p>
</body>
</html>

Thanks for your time in advance.

4
  • please test your page using firebug addon of mozilla specifically see under Net panel's XHR tab if your web service accessible or not. Make sure there is no 500 internal server error or 404 resource not found exception is not coming. it looks clear by your question that your webservice is not being called Commented Jan 12, 2012 at 5:59
  • I checked using firebug. I'm not so familier with firebug too. but saw that there is nothing under "response" its empty but no error mesgs shown as error or something. Commented Jan 12, 2012 at 6:06
  • press ctrl+shift+k there you will find NET button see under that is your page is making request to webservice or not if there is no response means your script is not calling the webservice at all for sure Commented Jan 12, 2012 at 6:12
  • are you making a cross domain request to service if so then you should use jsonp request jsonp request using the $.json function notetodogself.blogspot.com/2009/02/… this link may help you but there should exit an jsonp api available by your webservice provider Commented Jan 12, 2012 at 6:18

3 Answers 3

3

its restricted by CORS you cannot access data across the domain, moreover the xml seems to have some formatting issues try the json format along with dataType:'jsonp'

$.ajax({
        type: "GET",
        url: "http://services.faa.gov/airport/status/IAD?format=json",
        dataType: "jsonp",
    success: function(data){
        alert("asd");
    console.log(data);
    }
        });

http://jsfiddle.net/WxMXR/7/

Sign up to request clarification or add additional context in comments.

Comments

1

There are error when I execute you js in http://jsfiddle.net/QYQ4V/2/

Because you are not allowed to use the ajax calls to fetch data from other domains ... (unless using the JSONP or script datatypes ..) JSONP: http://en.wikipedia.org/wiki/JSONP

So that mean you can use other language(python/ruby/java) to get the data and use jquery to fetch the data in the same domain rather than use XHR($.ajax) in jQuery.

Comments

0

FYI

The server side return xml and response http header 'Content-Type'='application/xml' which should be 'text/xml',

and low level XMLHttpRequest using 'application/xml', so that conflicts happened.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.