小编典典
最后,我通过使用json解决了这个问题。 首先,我创建getimages.php文件并读取该文件中的目录,并获取所有图像名称并将该名称存储在数组中。
getimages.php
$filenameArray = array();
$handle = opendir(dirname(realpath(__FILE__)).'/images/slider_images/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "images/slider_images/$file");
}
}
echo json_encode($filenameArray);
?>
从要动态加载图像的页面调用getimages.php。
index.php
$.ajax({
url: "getimages.php",
dataType: "json",
success: function (data) {
alert("success");
$.each(data, function(i,filename) {
alert(filename);
$('.slides').append('
});
}
});
这对我来说是完美的。 我要尝试这个。这是使用ajax从文件夹加载图像的非常简单的方法
2020-07-26