1

I'm creating a web application for a client and I'm having difficulty getting the XML data from the https://aviationweather.gov/ ADDS TextData Server. I am trying to pull the XML data and convert it to HTML in a specific paragraph of my website. Here is the TextData Server address that I'm using for XML: Aviation Weather

$("#findMETAR").click(function(event){
  var airport = $('#airportCode').val();
  $.ajax({
   type: "GET",                
                        url:"http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=TRUE&stationString="+encodeURIComponent(airport),
   dataType: "xml",
   success: processXML,
  });
   
    function processXML(xml) { 
        $("#metarData").html($(xml).find("raw_text").text());
    }
   
   
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Metar Finder</h1>
   <p class="lead white">Enter the airport ICAO airport code to find the most recent metar</p>
   <p id="metarData"><!--METAR DISPLAYED HERE--></p>
     <form>
      <div class="form-group">
        <input type="text" class="form-control" name="airportCode" id="airportCode" placeholder="e.g. KLAX, KDEN, KJFK..."/>
      </div>
      <button id="findMETAR">Find METAR</button>
     </form>
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • If you look at the console errors you should see that you are getting an error from the server indicating: `XMLHttpRequest cannot load http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource…pe=retrieve&format=xml&hoursBeforeNow=3&mostRecent=TRUE&stationString=KLAX. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.` This is a `Same Origin Policy' error. – David Tansey Oct 14 '15 at 00:58
  • The following post may be of help: http://stackoverflow.com/questions/19821753/jquery-xml-error-no-access-control-allow-origin-header-is-present-on-the-req – David Tansey Oct 14 '15 at 01:00

0 Answers0