我想在單個頁面上顯示來自遠程服務器的多個圖像,該頁面是一個HTML文件,其中的php塊將不會做任何事情來獲取我想要的東西用ajax響應顯示多個圖像
使用PHP 5.6版本中,PHP代碼
$dir = "uploads/image/dashed/";
$files = scandir($dir);
foreach ($files as $file)
{
if (is_file($dir. $file)){
echo $file;
}
}
Ajax響應代碼:
$(document).ready(function(){
$.ajax({
async: true,
type: 'POST',
url: 'folder.php',
success: function(data){
$("#imageContent").html(data).append("<br/>");
var images = data.split("\n");
for (var i = 0, j = images.length; i < j; i++){
$("#imageContent").append("<img src='uploads/image/dashed/" + images[i] + "' width='300'>");
}
}
});
});
所有我一直從服務器得到的是 1354876944ABF.jpg_MG_0085.jpg 和一個空的圖像佔位(而不是兩個,正好一個),用於在圖像 和圖像地址示出了兩個圖像名稱中一個鏈路粘在一起
上傳/圖像/虛線/ 1354876944ABF.jpg_MG_0085.jpg
所述響應鏈路應該是在兩個(對於本示例)不同的行和圖像,其中<img>
是對AJAX調用中HTML
您正試圖通過換行分裂,但你的'echo'不回送一個換行符 –
好吧,我試圖在echo語句的末尾使用th
,它確實分解了這一行,但不顯示圖像,因爲它仍然是一樣的 –
'
'不是'\ n' –