Skip to content Skip to sidebar Skip to footer

Json Not Grabbed By $.getjson

Final solution: There was something wrong with the formatting of my .json file deeper down than the snippet I included in the question. Everything is working now. Big thanks to eve

Solution 1:

Using a slightly modified version of your code, I have it returning the JSON just fine:

http://plnkr.co/edit/DMLyJa1Quj7ofszn5Y7o?p=info

$(document).ready(function() {
  console.log("ready!");

  var items;

  $.getJSON('data.json', function(data) {
      console.log('json grabbed');
    })
    .done(function(data) {
      items = data.children;
      console.log(items);
    })
    .fail(function(data) {
      console.log("Error!");
    });

}); // close document.ready

Jquery uses .done now for the success method. In that block just assign your data.children item to a variable and you are good to go.

Solution 2:

Thanks to everyone in the comments I was able to sort out the issue. It was actually a JSON formatting issue. I used this site to find where the problem was: https://jsonformatter.curiousconcept.com/

Post a Comment for "Json Not Grabbed By $.getjson"