Click here to Skip to main content
15,878,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im kinda new to php + javascript.

I have set up "cute file browser" to look at a shared folder on my computer. it works fine displays all files & folders no problem.

Now im trying to use OMDB to search for movie posters and then display them for each movie name.

currently it works but only with the first movie title. when inspecting the element in FF it does show all the other posters but only within the first

The following displays my Seperate movie folders - no problems works fine....

What I have tried:

if(scannedFolders.length) {

scannedFolders.forEach(function(f) {

var itemsLength = f.items.length,
name = escapeHTML(f.name);

if(itemsLength) {
icon = '';
}

if(itemsLength == 1) {
itemsLength += ' item';
}
else if(itemsLength > 1) {
itemsLength += ' items';
getPoster(name);
}
else {
itemsLength = 'Empty';
}


var folder = $('
  • ' + name + '
  • ');

    folder.appendTo(fileList);
    });

    }


    now i want to add movie posters using omdb...

    JavaScript
    function getPoster(finfo)
    {
    	var filmName;
    	var realName;
    	filmName = finfo;
    	realName = filmName.split('.')[0];
    	var omdbUrl = "http://www.omdbapi.com/?t=" + realName;			
    	//document.getElementById("songdisplay").innerHTML = url;	
    	
    	                $.ajax({
                        url: omdbUrl,
                        //force to handle it as text
                        dataType: "text",
                        success: function(data) {
                            
                            //data downloaded so we call parseJSON function 
                            //and pass downloaded data
                           var json = $.parseJSON(data);
                            //now json variable contains data in json format
                            //let's display a few items
                            document.getElementById("folders").innerHTML += "<img id='imgposter'  class='imgPoster'  src='" + json.Poster + "'></img>";
                        }
    	
    					});
    
    	
    }



    but everything is displayed within the first folder rather than putting each image into its own LI....

    https://i.stack.imgur.com/qHhdS.jpg

    any help would be great thanks
    Posted
    Updated 5-Jul-20 19:21pm

    1 solution

    We'll this code
    document.getElementById("folders").innerHTML += "<img id='imgposter'  class='imgPoster'  src='" + json.Poster + "'></img>";

    Does not try to put anything in it's on LI.
    It just adds it to the 'folders' container;

    I'm also doubting that you understand that the getPoster function will be asyncronised.
    So the code
    var folder = $('' + name + '');
    
    folder.appendTo(fileList);


    Will run before the getPoster function has finished
     
    Share this answer
     

    This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



    CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900