0

I have a local json file

[{"image": "//www.dw.com/image/0,,18610867_301,00.jpg",
 "link": "//www.dw.com/en/alcoa-splitting-up-amid-commodity-slump/a-18746568",
 "heading": "Alcoa splitting up amid commodity slump"},

 {"image": "//www.dw.com/image/0,,18742245_301,00.jpg",
 "link": "//www.dw.com/en/kenya-ghetto-classics/a-18742091",
 "heading": "Kenya Ghetto Classics"},

 {"image": "//www.dw.com/image/0,,18045608_301,00.jpg",
 "link": "//www.dw.com/en/rajoy-seeks-talks-after-catalonia-election-win/a-18746178",
 "heading": "Rajoy seeks talks after Catalonia election win"},

 {"image": "//www.dw.com/image/0,,18746472_301,00.jpg",
 "link": "//www.dw.com/en/saudi-led-coalition-strikes-wedding-party-in-yemen-killing-scores-of-civilians/a-18746445",
 "heading": "Saudi-led coalition strikes wedding party in Yemen, killing scores of civilians"}]

Now I want to read it from another javascript file and present the information in a nice table. For the table visuliztaion I want to use keen.io but problem is that I cannot read the json file and return it literally that is I do not need to change the data I just need to read the data and plug it in keen.io

I have been trying the following code

$(document).ready(function() {
      var data = $.getJSON('data/web_stories.json', function(data) {
        dataStories = data
                               });

  Keen.ready(function(){
       var multipleEvents = {
        "stories": data

           }

// Send multiple events to several collections
client.addEvents(multipleEvents, function(err, res){
  if (err) {
    console.log('there is an error!')
  }
  else {
    console.log('data sent')
  }
});

But it doesn’t seem go work I get the following error: 400 (Bad Request)

Imo
  • 1,455
  • 4
  • 28
  • 53
  • You need to serve the file from a server. The web page won't read local files. – dievardump Sep 28 '15 at 15:50
  • You haven't said anything about your web server. Are you hosting the file data/web_stories.json on your server with that path? – bhspencer Sep 28 '15 at 15:50
  • @bhspencer Does it matter? – Lazy Sep 28 '15 at 15:51
  • @Lazy Probably, because of CORS – Scott Sep 28 '15 at 15:52
  • Where are you getting 400 error? – Lazy Sep 28 '15 at 15:53
  • I am getting 400 at http://localhost:9000/webpage.html, I am viewing it through grunt serve, I am actually trying to send the data to keen.io's server and then retrieve it from there for visualization, I am getting 400 at the point where I am sending the data. – Imo Sep 28 '15 at 15:57
  • Please take a look at this [Parse JSON from local url with JQuery][1]. it might solve your problem. [1]: http://stackoverflow.com/questions/8021022/parse-json-from-local-url-with-jquery – Mohamed HAMROUN Sep 28 '15 at 15:59

0 Answers0