0

I'm 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

This is the code i made for the OMDB...

var filmName;
var realName;
filmName = finfo;
realName = filmName.split('.')[0];
var omdbUrl = "http://www.omdbapi.com/?t=" + realName;          


                $.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>";
                }

                });

And this is the code for displaying my movie folders:

        if(scannedFolders.length) {

            scannedFolders.forEach(function(f) {

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

                if(itemsLength) {
                    icon = '<span class="icon folder full"></span>';
                }

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


                var folder = $('<li id="folders" class="folders"><a href="'+ f.path +'" class="folders"><span class="name">' + name + '</span></a> </li>');

                folder.appendTo(fileList);
            });

        }

This is the error i get

enter image description here

As i said i am new here. if anyone could give me any tips would be great thanks

Christian Lundahl
  • 2,000
  • 3
  • 18
  • 29
Pegatron
  • 1
  • 1
  • See [How to print all the txt files inside a folder using java script](http://stackoverflow.com/questions/37634049/how-to-print-all-the-txt-files-inside-a-folder-using-java-script/37634328?s=9|0.8271#37634328) – guest271314 Dec 11 '16 at 21:54
  • i can already see all files within folders? im trying to pull an image from the json results from OMDB from each individual movie it has already searched for – Pegatron Dec 11 '16 at 21:56
  • What is `data`? `html` or `JSON`? – guest271314 Dec 11 '16 at 22:10
  • the data comes from omdb as JSON. - as iv said, i can get it too display one file.. but not the rest http://imgur.com/vFisZ0A – Pegatron Dec 11 '16 at 22:13
  • _"the data comes from omdb as JSON"_ What is purpose of `var json = $.parseJSON(data);`? – guest271314 Dec 11 '16 at 22:14
  • it holds the data from omdb. I.E.. JSON.title, JSON.year, JSON.poster – Pegatron Dec 11 '16 at 22:19
  • Yes, is `data` a `javascript` object of `JSON` string? Where to you call `if(scannedFolders.length) {}`? – guest271314 Dec 11 '16 at 22:22
  • Scan.php searchs my $dir for any files and folders. Which then passes it to my javascript file where if(scannedFolders.length) {} is called. http://tutorialzine.com/2014/09/cute-file-browser-jquery-ajax-php/ – Pegatron Dec 11 '16 at 22:29
  • `jQuery.ajax()` `success` callback function returns results asynchronously, see http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call/. Place `if(scannedFolders.length) {}` after `document.getElementById("folders").innerHTML += ""` within `success` callback function. Where is `scannedFolders` defined? – guest271314 Dec 11 '16 at 22:42
  • tried that. Here is the full code for my javascript file: http://pastebin.com/HR8nXY78 it works with one picture its asif it isnt looping around and displaying the rest of the posters – Pegatron Dec 11 '16 at 22:48
  • See http://stackoverflow.com/help/how-to-ask, http://stackoverflow.com/help/mcve – guest271314 Dec 11 '16 at 22:49
  • im sorry your unable to understand my question. i did read through that before my original post. If you didnt know how to help you didnt have to answer. no need to point me in the direction of how to write a post. – Pegatron Dec 11 '16 at 22:54

0 Answers0