This is how I add the images inside the <div id = 'book'>....</div> . Unfourtunely it does not create any img tag as I expected. What is the error? The paths is confirmed contains value .
$('#book').append('<img src ="' + paths[1] + '" style = "width:100%;height:100%;top:1px;left:1px" alt = "flip book" id = "logo-cover" />');
Update:
This may due to the path[1] value , it is using for loop to iterate an array
it is possible an empty value, but it should be skipped as i have checked before append…
Whole script
<script>
function load_pages(page) {
$.ajax({
type: "GET",
url: "scandir.php",
data: "page=" + page,
dataType: 'json',
success: function (data) {
console.log(data);
$.each(data, function(i,paths){
var status = 'nonFinal';
if (paths[0] == '' && i == 'next'){
status = 'suspectFinal';
}
if (paths[1] == '' && i == 'next' && status == 'suspectFinal'){
status = 'final';
page--;
load_pages(page);
status == 'nonfinal'
}
else{
if (paths[0] != ''){
console.log('method called');
$('#book').append($('<img>').attr('src',paths[0]).css({'width':'100%','height':'100%','top':1px;}).attr('id','logo-cover'));
}
if (paths[1] != ''){
console.log('method2 called');
$('#book').append($('<img>').attr('src',paths[1]).css({'width':'100%','height':'100%','top':1px;}).attr('id','logo-cover'));
}
}
});
}
});
}
$(document).ready(function(){
var inputPage = '1';
if (inputPage == '1'){
inputPage = '2';
}
load_pages(inputPage);
});
</script>
Your posted code is correct, I used it to create this working jsFiddle: http://jsfiddle.net/Ah87q/
You should check if
paths[1]is not null, or you chould find the error somewhere else.