cameronstark
4/23/2017 - 1:39 PM

loadJSON - Alternative to jQuery getJSON

loadJSON - Alternative to jQuery getJSON

function loadJSON(path, callback) {
  var xobj = new XMLHttpRequest();
  xobj.overrideMimeType("application/json");
  xobj.open('GET', path, true);
  xobj.onreadystatechange = function() {
      if (xobj.readyState == 4 && xobj.status == "200") {
          // .open will NOT return a value but simply returns undefined in async mode so use a callback
          callback(xobj.responseText);
      }
  };
  xobj.send(null);
}