Welcome Guest. Sign in or Signup

2 Comments

How to load all files from directory using JQuery ?

Asked by: 22141 views e) Advanced

+1
0

Sometimes we might have a situation to load all the files from the directory, may be the file name is unknown, we can use this approach to load the files.


var dir = "Src/themes/base/images";
    var fileextension=".png";
      $.ajax({
         //This will retrieve the contents of the folder if the folder is configured as 'browsable'
            url: dir,
            success: function (data) {
                //Lsit all png file names in the page
                $(data).find("a:contains(" + fileextension + ")").each(function () {
                    var filename = this.href.replace(window.location.host, "").replace("http:///","");               
                    $("body").append($("<img src=" + Dir + filename + "></img>"));
                });
            }
        });

2 Comments



  1. techques on Jan 23, 2014 Reply

    Can you elaborate briefly ….
    Can i have a demo with this ?



  2. beyonds on Jul 29, 2014 Reply

    $(document).ready(function(){
    var dir = “img/”;
    var fileextension=”.jpg”;
    $.ajax({
    //This will retrieve the contents of the folder if the folder is configured as ‘browsable’
    url: dir,
    success: function (data) {
    //Lsit all png file names in the page
    $(data).find(“a:contains(” + fileextension + “)”).each(function () {
    var filename = this.href.replace(window.location.host, “”).replace(“http:///”,”");
    $(“#view”).append($(“”));
    });
    }
    });
    })

    i change it a bit , and it’s seem work for me.


Sponsored By:

Comments on Question