Jquery and php not working to load images onto screen from folder -


i have folder images in , trying load images file onto webpage. know images in correct format , dir correct. images not appearing on page. html file.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> $(document).ready(function() {     $.ajax({         url: "loadimages.php",         datatype: "json",         alert("this working");         success: function(data) {              $.each(data, function(i, filename) {                 $('#imgs').prepend('<img src="' + filename + '"><br>');             });         }     }); }); </script> <html>     <body>      <div id="imgs">     </div> </body> </html> 

this php file.

<?php $filenamearray = [".png"];  $handle = opendir(dirname(realpath(__file__)).'/images/');     while($file = readdir($handle)){         if($file !== '.' && $file !== '..'){             array_push($filenamearray, "/images/$file");         }     }  echo json_encode($filenamearray); ?> 

all need images shown on page.

you don't appear concatenating variables correctly

array_push($filenamearray, "/images/$file");

needs be:

array_push($filenamearray, "/images/".$file.");

if you're still having issues, post json?


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -