在https://aviationweather.gov/上使用AJAX从TextData Server获取XML数据时遇到问题

时间:2015-10-14 00:14:16

标签: javascript ajax xml

我为客户创建了一个Web应用程序,而且我很难从https://aviationweather.gov/ ADDS TextData Server获取XML数据。我试图拉取XML数据并将其转换为我网站的特定段落中的HTML。以下是我用于XML的TextData Server地址: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>
&#13;
&#13;
&#13;

0 个答案:

没有答案