I was having trouble trying to make this code work. I really don't see anything wrong with the javascript. When I debug, I don't find errors either.
<head>
<style type="text/css">
</style>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#Presentation').click(function() {
var jsonloc = "ppt.json";
$.when($.getJSON(jsonloc)).then(function(info){
$('#header').empty();
$.each(info.slides, function(entryIndex, entry){
var html = '<div class="info">';
html += '<h3>' + entry['title'] + '</h3>';
html += '<div class="author">' + entry['author'] + '</div>';
if(entry['slides']){
$.each(entry['slides'],function(slideIndex, slides){
html += '<h3>' + slides['Slide'] + '<h3>';
html += '<div class="header">' + slides['header'] + '</div>';
});
if(slides['Content']){
html += '<div class="Content">';
html += '<ol>';
$.each(slides['content'],function(contentIndex, content){
html += '<li>' + content + '</li>';
});
html += '</ol>';
html += '</div>';
};
$('#header').append(html);
};
});
return false;
});
});
});
</script>
</head>
<body>
<a href="#" id="Presentation">ppt presentation</a>
<div id="header">
</div>
</body>
here is the JSON:
{
"title": "presentation",
"date_created": "",
"last_modified": "",
"author": "By: Someone online",
"slides": [
{
"Slide": "1",
"header": "first header",
"src": "ssss.jpg",
"Content": "dddddddddddddddddddddddddddddddddddd",
"Content": "dddddddddddddddddddddddddddddddddddd",
"Content": "dddddddddddddddddddddddddddddddddddd"
},
{
"Slide2": "2",
"header2": "header 2",
"src2": null,
"Content": "dddddddddddddddddddddddddddddddddddd",
"Content": "dddddddddddddddddddddddddddddddddddd",
"Content": "dddddddddddddddddddddddddddddddddddd"
},
{
"Slide3": "3",
"header3": "header3",
"src3": "sdfdsf.jpg",
"Content": "dddddddddddddddddddddddddddddddddddd",
"Content": "dddddddddddddddddddddddddddddddddddd",
"Content": "dddddddddddddddddddddddddddddddddddd"
}
]
}
I really want to make this work and don't want to use other methods such as jquery templates. Is there anything that jumps out?
jsonfile with the same keys multiple times, because you won't be able to retrieve the value for Content`