/ / JSON + jQuery funktioniert nicht - Javascript, Jquery, HTML, Json

JSON + jQuery funktioniert nicht - Javascript, jquery, html, json

Ich versuche, dass jQuery die JSON-Datei übernimmt und die Daten auf einer einfachen Site ablegt, wenn eine Schaltfläche gedrückt wird. Der JSON-Code sieht also so aus:

{
"images" : [
{ "source" = "images1", "alternative" = "altImg1" },
{ "source" = "images2", "alternative" = "altImg2" },
{ "source" = "images3", "alternative" = "altImg3" }
]
}

Und die HTML + jQuery:

<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>

<body>
<button>Press Me!</button>
<script>
$("button").click(function()    {
$.getJSON("json-db.html", function(data)    {
for(var i = 0; i < data.images.length; i++) {
var image = data.images[i];
$("#result").append("<h1>" + image.source + " " + image.alternative + "</h1>");
}
});
});
</script>
<div id="result">Result</div>
</body>
</html>

Es werden keine Fehler von Firebug erkannt. Ich habe den Code mehrmals umgeschrieben, nach Fehlern gesucht, mit einem ähnlichen Code usw. verglichen, konnte aber nichts finden.

Danke im Voraus!

Antworten:

3 für die Antwort № 1

Ihre Json-Notation ist falsch

benutzen : Anstatt von = mögen:

..........
"images" : [
{ "source" : "images1", "alternative" : "altImg1" },
....................
]
..........