这是我的 html 测试页面:
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<style type="text/css">
#imager img{
width: 1050px;
height:650px;
}
</style>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var index = 0;
var max = 1;
//! get next image
function getImage(){
if (index >= max ) index = 0;
var objTest = {
"index" : index++
};
$.ajax({
type: 'POST',
url: "prova.php",
data: objTest,
success: function(response){
max = response.max;
imageToLoad = response.imageToLoad;
//! Clean div
$("#imager").html("");
//! Display new image
$("#imager").append("<img src='"+imageToLoad+"'></img>");
},
dataType: "json"
});
}
</script>
</head>
<body>
<button onclick="getImage()">get img</button>
<div id="imager"></div>
</body>
这是我的 prova.php 测试页面:
$max = 0;
$imgToLoad = null;
// Open image dir
if ($handle = opendir('img')) {
while (false !== ($entry = readdir($handle))) {
if($entry == '.' || $entry == '..' ) continue;
if($_POST['index'] == $max)
// Save next image to show
$imgToLoad =$entry;
// Image counter
$max++;
}
closedir($handle);
}
$array = array(
"max" => $max,
"imageToLoad" => "http://192.168.1.96/prove/cache/img/".$imgToLoad
);
// Return next image and max number of image the we can show
echo json_encode($array);
问题是每次我调用“getImage()”时,内存浏览器都会增加(IE 和 Firefox 测试)。我的“img”文件夹包含很多非常大的图像,大约 4600x3000px (400kb),一段时间后内存浏览器大约为 1 gb,依此类推。
感谢帮助