I have code similar to this in JSFiddle . On my WAMP server at home I tried to work with JSON (JSFiddle does not contain the JSON file to test).
In a question I asked about how to insert data into a database with jQuery answered me that it would be a good option to store the data in JSON files. The answer author showed me what the syntax of the JSON file would look like. You said you could do the following:
[
{ titulo: 'ET', ano: 1982 },
{ titulo: 'Indiana Jones', ano: 1981 }
]
In my tests with this jsfiddle code worked well when the JSON file was in the format:
{
"Titulo": "Até que a sorte nos separe",
"segundo": "segundo valor",
"terceiro": "terceiro valor, o ultimo valor não precisa de virgula"
}
But when I put in the format that the author of the answer to my first question showed, clicking on the "Click me to list" link does not fire anything.
I would like to know the difference between the two syntaxes, because I want to make a small website with a small database with information about the movies I've watched and the ones I'm still going to see. A link on where to get this information from how to mount a JSON file and how to access those values would be a good one.
I use the $.ajax()
method to retrieve my JSON that is inside a * .json file as per code:
$.ajax({
url: 'js/vendor/testedb.json',
dataType: 'json',
success: function(data) {
var item = [];
$.each(data, function(key,val) {
item.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>',{
'class': 'myclass',
html: item.join('')
}).appendTo('body');
},
statusCode: {
404: function() {
alert("some problem");
}
},
});