arbeitet Ich versuche, Daten von Json-Datei mit getJSON Funktion zu erhalten:getJSON dann nicht
$.getJSON("uploads/data.json").then(function(data) {
allData = data.sculptures;
locations = {};
for(var i=0; i<data.location.length; i++) {
locations[data.location[i].name] = data.location[i].location;
}
console.log(allData);
console.log(locations);
});
Aber ich bin nicht immer alles. Wenn ich diesen Code in Chrome Konsole Entwickler-Tool lief, es zeigt nur das:
Object {}
always:()
done:()
fail:()
pipe:()
progress:()
promise: (a)
state:()
then:()
__proto__: Object
Diese data.json ist:
{"sculptures":[{"title":"Bust of Caracalla","location":"Paris"},
{"title":"Brutus The Younger","location":"Paris"}],
"location":[{"name":"Beaux-Arts in Dijon, France","location":{"lat":47,"lng":5}},
{"name":"Louvre, Paris","location":{"lat":48,"lng":2}},
{"name":"St Pauls Cathedral, London","location":{"lat":51,"lng":-0}},
{"name":"V&A, London","location":{"lat":51,"lng":-0}}]}
[Ihr Code funktioniert] (https: // jsfiddle. net/jsucwvwe /). Etwas anderes passiert. – Andy
@Andy es ist etwas mit $ .getJSON verwandt, aber ich kann nicht herausfinden, – julie
http://StackOverflow.com/Questions/18637418/trying-to-load-local-Json-File-to-show-data-in -a-html-page-using-jquery – Andy