HTML/[removed] Iterate through all elements of local (server-side) folder

前端 未结 2 814
醉梦人生
醉梦人生 2021-01-20 18:21

Basically, I have a very simple website where the root directory looks like:

/images/
index.html
stuff.js

I want some way to recursively it

2条回答
  •  执笔经年
    2021-01-20 18:46

    Perhaps the best way to do this is to use a server-sided language to do it for you, and to use an asynchronous Javascript request to display the data.

    This sample uses PHP to list all the files in a specified directory, and an xmlhttprequest to load this output and convert the results into image tags:


    getimages.php:

    
    

    index.html (same directory as getimages.php):

    
    
        
            Image List Thing
        
        
    
            

    Note that this is only an example. You'll probably want to make sure that the AJAX call is successful, and that the JSON conversion works both in the server code and on the client.

提交回复
热议问题