这是我第一次将Ajax与Jquery,PHP和Mysql结合使用而无需进行页面刷新。 Testpage
是否可以在php中添加网址? 1 => /index.php?page=1
2 => /index.php?page=2
现在我只有index.php。
我想要实现的示例(https://www.komputronik.pl/producer/51/amd.html?showProducts=1&p=3&showBuyActiveOnly=0)
更新1 添加的history.pushStat
现在显示public/1
public/2
...
但是当我转到产品详细信息(show.php?id=96
)时,我无法返回。
show.php <a class="goback" href="#" onclick="window.history.go(-1); return false;">« Go back </a>
$(document).on('click', '.pagination_link', function(){
//e.preventDefault();
var page = $(this).attr("id");
load_data(page);
history.pushState(null, null, $(this).attr('id'));
historyedited = true;
});
1。 Ajax(index.php)
<script>
$(document).ready(function(){
load_data();
function load_data(page)
{
$.ajax({
url:"pagination2.php",
method:"GET",
data:{page:page},
success:function(data){
$('#page').html(data);
//alert('Successfully called');
},
//error:function(exception){alert('Exeption:'+exception);}
})
}
//load_data(1);
$(document).on('click', '.pagination_link', function(){
var page = $(this).attr("id");
load_data(page);
});
});
</script>
2。链接(pagination2.php)
if($page_nb > 1) {
//echo "<a href='index_all.php?page=".$prev_page."'>Back</a>";
echo "<span class='pagination_link' style='cursor:pointer;' id='".$prev_page."'>Back</span>";
}
if ( $products_count > $check ) {
for ( $i = max( 1, $page_nb - 5 ); $i <= min( $page_nb + 5, $limit ); $i++ ) {
if ( $current_page == $i ) {
echo "<span class=\"selected\">{$i}</span>";
} else {
//echo "<a href=\"{$url}?page=" . $i . "\">{$i}</a>";
echo "<span class='pagination_link' style='cursor:pointer;' id='".$i."'>".$i."</span>";
}
}
}
if ($products_count > $check) {
$next_page = $page_nb + 1;
//echo "<a href='index_all.php?page=".$next_page."'>Next</a>";
echo "<span class='pagination_link' style='cursor:pointer;' id='".$next_page."'>Next</span>";
}