Re: [CODE4LIB] including data from static JSON file in Javascript

2016-04-06 Thread Ken Irwin
tion! Ken From: Code for Libraries [CODE4LIB@LISTSERV.ND.EDU] on behalf of Kyle Banerjee [kyle.baner...@gmail.com] Sent: Wednesday, April 06, 2016 9:45 PM To: CODE4LIB@LISTSERV.ND.EDU Subject: Re: [CODE4LIB] including data from static JSON file in Javascript If all you wan

Re: [CODE4LIB] including data from static JSON file in Javascript

2016-04-06 Thread Conal Tuohy
Ken, you can make a synchronous request with XMLHttpRequest if you need to (though it's not commonly done): var request = new XMLHttpRequest(); request.open('GET', 'data.json', false); // false implies synchronous request.responseType="json"; request.send(null); But do consider the option of mak

Re: [CODE4LIB] including data from static JSON file in Javascript

2016-04-06 Thread Kyle Banerjee
If all you want to do is load external json as a string, you can do it using syntax almost identical to what you suggest. Just change your data.json file so the content is var data = ' [include your json here, be sure to escape things properly]'; Then just load this file before your external scri

[CODE4LIB] including data from static JSON file in Javascript

2016-04-06 Thread Ken Irwin
Hi folks, I'm working on a javascript project that currently has a bunch of JSON data defined inside the script; I'd like to move the data to a file outside the JS file so it can be updated without touching the script, but I'm running up against a few challenges externalizing the data. The sta