0

I am creating a weather based artwork-change to be hosted on a local machine with the JSON file updating through an FTP sync. This means that the JSON file will be sourced locally on the same computer. Below is my current code for sourcing the JSON externally. Could you help me with sourcing this locally. Would I just change the URL to the file pathway of where it will be sitting? and remove the GET and send parts.

var xhr = new XMLHttpRequest();

var URL = "http://api.openweathermap.org/data/2.5/weather?q=   {London}&appid=genericAPIpassword";

xhr.open("GET", URL, false);
xhr.send();

var weatherResponseStringify = JSON.stringify(xhr.responseText, "", 2);
var weatherResponseParse = JSON.parse(xhr.responseText);

Thank you all for helping!

D.Golabi
  • 13
  • 3
  • by local, do you mean there's no server involvement at all (i.e., file:/// rather than http:// for the web page – Jaromanda X Feb 09 '16 at 09:43
  • `JSON.stringify` and `JSON.parse` on the same result ... odd thing to do – Jaromanda X Feb 09 '16 at 09:44
  • Yeah this will be a file:/// rather than using an external server. It's to by-pass a whitelisting issue. As to the stringify/parse I used the first to read out the JSON file and the second to use it. I can actually remove the first now. – D.Golabi Feb 09 '16 at 09:59
  • Chrome for one wont like it (xmlhttprequest on file:///) without a command line argument – Jaromanda X Feb 09 '16 at 10:42

1 Answers1

0
var myInternalSource = {
  key:value,
  key:value
}

No need to overcomplicate things. If the json is in another file, then do:

<script src="externalFile.js" ></script>

Or use System.JS Import if you need asychronisity.

Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
  • I would normally agree with just copy/pasting the JSON data, but basically this is a weird situation where the JSON file would be synced via and FTP to a local folder every 10 minutes or so and would update this way. So the JS would need to be able to update in line with the changing content of the JSON file. I could source this into html, but I would need to run most of my JS as a – D.Golabi Feb 09 '16 at 09:57