Click here to Skip to main content
14,487,386 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to fetch and print raw_text from the xml API using Jquery.

I have successfully run the ajax call to trigger the API .
<pre><response xmlns:xsd="" xmlns:xsi="" version="1.2" xsi:noNamespaceSchemaLocation="">
<data_source name="metars"/>
<request type="retrieve"/>
<data num_results="6">
KDEN 141753Z 36022G34KT 10SM FEW080 SCT130 BKN180 M02/M08 A3011 RMK AO2 PK WND 35036/1703 SLP217 60000 T10221083 11022 21039 51023
<sky_condition sky_cover="FEW" cloud_base_ft_agl="8000"/>
<sky_condition sky_cover="SCT" cloud_base_ft_agl="13000"/>
<sky_condition sky_cover="BKN" cloud_base_ft_agl="18000"/>

What I have tried:

ow i am trying to get a value of raw_text. 

<pre lang="Javascript">$.ajax({
			type: "GET",
			url: "",
			dataType: "xml",
			data: { 
			success: function(data) {
			//remainder of the code
                       console.log(data.METAR.raw_text) // not able to get this value

Updated 14-Mar-19 18:25pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Assuming the XML posted here is correct, you can use the .find() selector to get the element value like below. Again, I have to assume that the data return is XML type object.


if not, here an example on how to parse a string into XML object
Cp_xml find node - JSFiddle[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100