我正在考虑做一个动态的图片库,我正在寻找一个与 facebook 类似但使用 url 哈希的解决方案。
我想收到有关这种类型的调用 ajax 的详细信息,以便在不刷新页面的情况下动态获取信息,这是我正在寻找的正确方法吗?旧浏览器有问题?
<html>
<head>
//jquery.js
</head>
<body>
<!-- #nameimage is the name of the big image that will be loaded,
so this hash will be used for the call ajax. -->
<a href="#nameimage1"><img src="url-thumb-image1"></a>
<a href="#nameimage2"><img src="url-thumb-image2"></a>
<a href="#nameimage3"><img src="url-thumb-image3"></a>
<a href="#nameimage4"><img src="url-thumb-image4"></a>
<div class="image-big"></div>
</body>
</html>
jQuery
$(document).on('click','a', function(){
var hash = window.location.hash; // nameimage
// very simple ajax
BASE_URL = 'http://localhost/';
$.ajax({
type: "POST",
url: BASE_URL + 'get_image',
data: "name_image=" + hash,
success: function(result) {
// print result on div
$('.image-big').html(result);
},
error: function(){
alert('Error on ajax call');
}
});
});
PHP
<?php
$name_image = $_POST['name_image'];
$path = 'main_folder/image/';
echo '<img src="'.$path.$name_image.'.jpg">';
// and i can cache the results
?>