S
S
Sergey Suntsev2016-04-08 13:16:56
JavaScript
Sergey Suntsev, 2016-04-08 13:16:56

What is the peculiarity of loading data via $.getJSON?

I load json data from a file and pass it to a variable.

var tests;
var data = $.getJSON( "html.json", function() {
  tests = JSON.parse(data.responseText);
});


Then I process them through the lodash template engine.

var genListData = _.template(document.getElementById('list-template').innerHTML);
document.write(genListData(tests[1]));


When the data is not in a separate file, but immediately in a variable, then everything is fine, everything works.
var tests ={ some json };

But I don’t want to constantly flatter the script when updating the data. It's much more convenient to have a separate JSON file. Tell me, maybe I did not take into account something when uploading the file?

UPD// when reloading the page, I found that sometimes the file still has time to load and everything works, but this rarely happens.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question