Skip to content Skip to sidebar Skip to footer

Problems Reading Json File In D3 Javascript In Some (not All) Browsers

I get this error in Chrome immediately after reading a JSON file. It works correctly in Safari and Firefox. console.log ('event -> '+ postcards.nodes[0].node.event); // 'tally'

Solution 1:

Does the following work for you?

Promise.all(
  d3.json("/sites/default/d3_files/json/toronto-wards.json"),
  d3.json("/postcards-json")
)
.then(
  function([wards,postcards]) {
    console.log ("event -> "+ postcards.nodes[0].node.event); // tally in Safari

Some browsers may not support deconstructing arrays so probably better to try the following for older browsers (non Chrome and Firefox):

Promise.all(
  d3.json("/sites/default/d3_files/json/toronto-wards.json"),
  d3.json("/postcards-json")
)
.then(
  function(results) {
    var wards=results[0],postcards=results[1];
    console.log ("event -> "+ postcards.nodes[0].node.event);
  }
);

According to the comments your drupal end point providing the JSON needs authentication so gives you empty data when you're not loged in.

Error has maybe nothing to do with the browser used but depends if you're loged in or not.

Solution 2:

The problem was caused by the Drupal view not being created correctly. Nothing to do with the Chrome browser.

Post a Comment for "Problems Reading Json File In D3 Javascript In Some (not All) Browsers"