i am having trouble fetch JSON using jQuery, if possible someone tell me what mistake i made because my code is not working
data.json file contain
{
"value1",
"value2",
"value3",
"value4"
}
and here is my jquery code
$.getJSON( "data.json", function( data ) {
$.each( data, function( val ) {
alert(val);
});
});
use
[]
instead of{}
in the json file as suggested in the comment as your current json is not a valid JSON. Then you can access the file data this way.Notice, that your current code only access the index of the value but not the actual value. Place the both parameter
i
andval
to get both index and value from the file.DEMO