0

I have a json file, that includes:

{
    "data": [{
        "red": "#f00",
        "green": "#0f0",
        "blue": "#00f",
        "cyan": "#0ff",
        "magenta": "#f0f",
        "yellow": "#ff0",
        "black": "#000"
    }]
}

And I want to put that data and alert it with a jquery code, the .json file is located on localhost in a neighbouring folder

Tushar
  • 85,780
  • 21
  • 159
  • 179
SJWimmer87
  • 73
  • 3
  • 7

2 Answers2

0

Try this:

$.getJSON( json path, function( data ) {
    alert(data);
});
Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38
0

This will load the data from the file

var jsonData = {};
$.getJSON('fileName',function(data){
    alert(JSON.stringify(data));
    jsonData = data;
});
Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
Shubham
  • 1,755
  • 3
  • 17
  • 33
  • It works, but it puts the whole data with "{[{}]}"etc, into the variable too, and I have to put that into a html table, like an array. (with mustache.js) – SJWimmer87 Nov 10 '15 at 08:51