0

I found a code snippet showing how to fetch data from a JSON array:

<div id="placeholder"></div>
<script>
var data={"users":[
    {
        "firstName":"Ray",
        "lastName":"Villalobos",
        "joined":2012
    },
    {
        "firstName":"John",
        "lastName":"Jones",
        "joined":2010
    }
]}

document.getElementById("placeholder").innerHTML=data.users[0].firstName + "    " + data.users[0].lastName+" "+ data.users[0].joined;
</script>

But I want the data in a JSON File. So how can I do this?

ab2211
  • 11
  • 3

1 Answers1

1
$.getJSON('example.json', function (data) {
    console.log(data);
  });
Marsovski
  • 11
  • 2
  • Thanks, that helped! I need the parameter "function" . For the local test I use a chrome extension (enable cross-origin resource sharing). – ab2211 Dec 16 '16 at 22:53