javascript - loading images from e folder and display them in html -
hi guys using following code trying read images folder , display them in html file. problem how can see /images/ folder in /fetch/ folder. when images displayed loaded /fetch/frame_1.jpg instead /fetch/images/frame_1.jpg in case display them have use twice images set. 1 in image folder , 1 in fetch folder. can explain me why this?
<body> <script type="text/javascript"> var dir = "/fetch/images/"; var fileextension = ".jpg"; $.ajax({ url: dir, success: function (data) { $(data).find("a:contains(" + fileextension + ")").each(function () { var filename = this.href.replace(window.location.host, "").replace("http://", ""); $("body").append("<img src='"+ filename + "'>"); console.log(filename); }); } }); </script> </body>
two changes got me images. 1) remove forward/back slash var dir. 2) combining dir , name of file.
below code worked me:
<body> <script type="text/javascript"> var dir = "fetch/images/"; var fileextension = ".jpg"; $.ajax({ url: dir, success: function (data) { $(data).find("a:contains(" + fileextension + ")").each(function () { var fn = this.href.replace(/^.*[\\\/]/, ''); var filename = dir + fn; $("body").append("<img src='"+ filename + "'>"); console.log(filename); }); } }); </script> </body>
Comments
Post a Comment