英文:
pass parameter to $.selector for ajax GET request call
问题
我使用循环来输出分页链接,类似这样的结构:'<< < > >>'。
在我的代码中,我通过 GET 请求设置了 $currentpage 变量:
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int)$_GET['currentpage'];
} else {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
我还有一个会话变量,用于保存用户在导航页面链接时选择的搜索条件。逻辑错误出现在用户点击任何分页链接时,会话变量被清除,表格显示时不带搜索条件。
经过深入研究,我发现可以使用 Ajax 来解决问题,但是我对如何实现目标感到困惑。以下是我尝试的方法,希望能得到一些帮助:
$('#pglink').click(function(e, $prevpage) {
e.preventDefault();
var pgNo = $prevpage;
$.ajax({
url: "file.php",
type: "get",
data: {
currentpage: pgNo
}
});
});
英文:
i have pagination links echoed with a for loop like this '<< < > >>".
echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>< </a>"
somewhere within my codes i set the $currentpage using GET request:
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])){
$currentpage = (int)$_GET['currentpage'];
}else{
$currentpage = 1;
}
//the offset of the list , based on current page
$offset = ($currentpage-1) * $rowsperpage;
and i have a session variable to hold search criteria selected by the user while he navigates the page links. The logical error i get is when user clicks any of the pagination link, the session variable wipes out and table displays without the search criteria.
After intensive research i figured out i can use ajax but am confused on how to arrive my goals. THis is what i tried doing. please some help will do.
$('#pglink).click(function(e,$prevpage){//***i need to pass the current page parameter for clicked link
e.preventDefault();
var pgNo = $prevpage;
$.ajax({
url:"file.php",
type: "get",
data:{
currentpage: pgNo }
});
});
专注分享java语言的经验与见解,让所有开发者获益!
评论