javascript - How can I load multiple html files from a folder into a div -
say i've got folder "../cars/" holds multiple html files, , want load of these files html file.
i go doing like:
$(document).ready(function (){ $("#all_cars").load("../cars/civic.html"); $("#all_cars").load("../cars/durango.html"); $("#all_cars").load("../cars/mustang.html"); $("#all_cars").load("../cars/r8.html"); ... , on });
but i'd in more sophisticated manner. don't want have code file names js file. i'd rather able remove file folder , have load anymore. there way filenames in cars folder , loop on them load?
kind of this:
foreach(cfn in carsfilesnames){ $("#all_cars").load("../cars/" + carsfilenames); }
hopefully want:
$.each([ 'civic.html', 'durango.html', 'mustang.html', 'r8.html' ], function(i,a){ $("#all_cars").load("../cars/" + a); });
$.each
go on array.
if wish automatically files in directory , list them, , have php on web server, add file called
carindex.php
, set it's content to: <?php print json_encode(scandir('path/to/cars/', 1)); ?>
then on client side:
$.get('/carindex.php', function (a) { a.foreach(function (b) { $("#all_cars").load("../cars/" + b); }); });
Comments
Post a Comment