所以而不是$.post
像你说的那样寻找$_GET['page']
所以你可以做这样的事情:
<script>
$(document).ready(function(e) {
var page_num = 1;
$('.nextpage').on('click',function(e){
e.preventDefault(); // stop the link from going anywhere
$.get('./page.php',
{
page: page_num // this is the same as $_GET['page']
},
function (data) {
$('#result').html(data);
page_num++;
}
);
});
$('.nextpage').click(); // emulate the click to get the first page
});
</script>
在你的身体里是这样的:
<a href="/page.php?page=2" class="nextpage">Next page</a>
值得注意的是,在你page.php
身上你不需要那个表格,因为我看不到它会做很多事情
更新
因此,要在index.php
from上操作分页,page.php
您可以page.php
返回一个隐藏的 div.hidden_pagination
及其全部内容。
<script>
$(document).ready(function(e) {
$('.pagination').on('click','a',function(e){
e.preventDefault(); // stop the link from going anywhere
var next_page = $(this).attr('data-id'); // get the next page from the link data-id attribute
$.get('./page.php',
{
page: next_page // this is the same as $_GET['page']
},
function (data) {
$('#result').html(data);
$('.pagination').html($('#result').children('.hidden_pagination').html()); // add the new pagination to the current pagination
}
);
});
$('.nextpage').click(); // emulate the click to get the first page
});
</script>
<div class="pagination">
<a href="#" class="nextpage" data-id="2">Next page</a>
</div>
<div id="result">
this will be replaced with the ajax response
</div>