0

I'm trying to load a local JSON file to populate a table with it. I've tried requireJS, but it gave me an error:

MODULE NAME ... HAS NOT BEEN LOADED YET FOR CONTEXT

So I installed the requireJS plugins with bower, though I'm not sure if they are working correctly. This is the code:

    <script src="require.js"></script>
<script>
    function populate() {
        require(['json!sortedAccounts.json'], function (json) {
            for (var i = 0; i < json.length; i++) {
                var $row = "<tr>"
                var account = json[i][0]
                $row.append("<td>" + account + "</td>")
                var friends = json[i][1]
                $row.append("<td>" + friends + "</td>")
                $row.append("</tr>")
                $('loadedJSON').append($row)

            }
        });

    }

</script>

The error I get is:

GET http://localhost:63343/HTML/json.js
Uncaught Error: Script error for "json", needed by: json!sortedAccounts.json_unnormalized2 Uncaught Error: Load timeout for modules: json!sortedAccounts.json_unnormalized2

0

1 Answer 1

0

As you are using jQuery you could simply do this:

$.getJSON( "sortedAccounts.json", function(json) {
      for (var i = 0; i < json.length; i++) {
            var $row = "<tr>"
            var account = json[i][0]
            $row.append("<td>" + account + "</td>")
            var friends = json[i][1]
            $row.append("<td>" + friends + "</td>")
            $row.append("</tr>")
            $('loadedJSON').append($row)  // Incorrect selector
      }
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.