0

We use the D3 JavaScript to initialize data documents, then build an application-specific JavaScript to process data.

A subset of the application-specific JavaScript looks like this:

   drawLegend();
   thousand_sep_format = d3.format(',');
   d3.json("http://wafi.iit.cnr.it/webvis/tmp/dbpedia/realOntology.json", function(error, root)

More specifically it correctly processes this JSON file:

   http://wafi.iit.cnr.it/webvis/tmp/dbpedia/realOntology.json

However, when we copy the original JSON file to another Linux/Ubuntu server, the copied JSON file cannot be processed.

Here is the copied JSON file:

   http://www.ontomatica.com/public/test/dbpedia_ontology/realOntology.json

What is the difference between JSON-original and JSON-copied?

What is the correct process to copy an original JSON file to a new server?

Our goal is to remove sections of the original JSON file and then plot the subset. Therefore we have to put a working subset on a server.

Jay Gray
  • 1,706
  • 2
  • 20
  • 36
  • 4
    Check console and network tabs. Scientific guess: same origin policy – zerkms Apr 06 '15 at 23:01
  • 1
    Based on glancing at the response headers from the two URLs and making the assumption that `d3` indicates that the code is running in a browser, then the answer will be found in the browser's developer tools' console and is a duplicate of [this](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy). – Quentin Apr 06 '15 at 23:03
  • @zerkms Could you give me a bit more information to follow - not sure what to look at. Further, we need the JS to read the URL and don't see a difference between the two URLs. – Jay Gray Apr 06 '15 at 23:04
  • @JayGray — The phrase [same origin policy](https://duckduckgo.com/?q=same+origin+policy&ia=about) is plenty of information to follow (as is the mention of the console which gives a pretty detailed error message for this in most browsers). – Quentin Apr 06 '15 at 23:05
  • "a bit more information to follow" 1. Check console and network tabs 2. Put the "same origin policy" into google – zerkms Apr 06 '15 at 23:05

1 Answers1

4

The first site responds with an Access-Control-Allow-Origin header with the value *. That tells browsers that they should allow xhr access to the site regardless of the originating domain.

The other site doesn't do that, so the browser won't fetch the content.

The problem has nothing to do with the URLs as such, nor with the JSON content. It's a matter of server configuration, and exactly how you change that depends on the hosting environment.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • 3
    ^This is likely the correct answer. Another difference that might cause issues is that www.ontomatica.com sends the content-type as 'text/plain' instead of 'application/json'. – HankScorpio Apr 06 '15 at 23:13