My weekend project; to create a working METAR grabber, that can take an XML document, such as this one from the FAA’s databases, and grab one XML element, to log it to the console.
Once this data is received, it will be implemented into a website called VATTASTIC that will read user input in the chat, and respond with a METAR. This piece of the puzzle is not the focus yet, and cannot be because I cannot access the data.
Here’s the code, and the error I’m getting:
METARBot.js:1 Uncaught SyntaxError: Unexpected identifier
I tried a version editing InnerHTML as well, with the same result:
Any help would be appreciated. Thanks.
I am not familiar with what you are working with, but I noticed one really simple thing. In your getTheXml function, you have an unnecessary semicolon before the closing parentheses. Just wanted to point that out.
I’ll take a look… Thanks.
No cigar there… Will be rewriting this with the new JSON format they released recently, something I’m more comfortable with. Thanks for the help.
Syntax errors should be fairly trivial to fix
Also, I suggest avoiding online “try it” apps, better use local files and open that in your browser, either by serving it with some http server (for example if you have python3 installed:
python -m http.server in the site directory) or directly from the file system. Sharing the source is probably most conveniently done with a git repository, though a compressed archive would get the job done in a pinch
Just copied and pasted it onto the try it apps online from my local files so I didn’t have to paste raw code here.
I suspect your browser would point out exactly where the syntax error is if you peek in its console
I just couldn’t figure out what that meant. Now I fixed it. Thanks.
After fixing that (though it’s not that line is it) - you’ll run into issues with same origin policy - I’m kind of clueless on that but it might be that the request needs to be done server-side, (unless you can coax your users into disabling that security feature in their browser, which seems unlikely)
If they have a different api, then yeah. That could get around this. https://en.wikipedia.org/wiki/JSONP
If this application of yours is supposed to run on a server (if it doesn’t need to show the data on the same page that you are using to request the xml) then it has no business running in a browser anyhow, in which case this api seems just fine
$ curl 'https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&re
<?xml version="1.0" encoding="UTF-8"?>
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" version="1.2" xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd">
<data_source name="metars" />
<request type="retrieve" />
<raw_text>PHTO 071353Z 23004KT 10SM FEW060 19/18 A2993 RMK AO2 SLP133 T01940178</raw_text>
<sky_condition sky_cover="FEW" cloud_base_ft_agl="6000" />
Thanks for the shot… I am, however, running it locally to run a bot myself. I don’t own the website nor server, so I’ll just be running the code myself.