ajax php分页不会显示活动页面

时间:2013-07-23 18:25:31

标签: php ajax pagination

我正在研究php ajax分页。

问题在于它不会正确地使用class =“highlightActivePage”。

如果我点击1 - 2 - 3,它会正常工作并突出显示第3页上的数字3。

但是,当我点击第4页时,它会突出显示第5页,等等。

不确定我的for循环是否错误,但在这里我们是我的代码:

if (paginationHTML == "")
        {

            paginationHTML += "<ul>";

            if (adResultsData.show_first_text == 1)
            {
                paginationHTML += "<li><a href='#' onclick='fetchResults(1);'>First</a></li>";  
            }

            if (adResultsData.show_previous_text == 1)
            {
                paginationHTML += "<li><a href='#' onclick='fetchResults(" + (adResultsData.current_page - 1) + ");'>Prev</a></li>";    
            }

            for (var i = 0; i < adResultsData.pages.length; i++)
            {
                if (adResultsData.current_page == (i + 1))
                {
                    paginationHTML += "<li><a href='#' class='highlightActivePage' onclick='fetchResults(" + adResultsData.pages[i] + ");'>" + adResultsData.pages[i] + "</a></li>";
                }
                else
                {
                    paginationHTML += "<li><a href='#' onclick='fetchResults(" + adResultsData.pages[i] + ");'>" + adResultsData.pages[i] + "</a></li>";
                }

            }

            if (adResultsData.show_next_text == 1)
            {
                paginationHTML += "<li><a href='#' onclick='fetchResults(" + (adResultsData.current_page + 1) + ");'>Next</a></li>";    
            }

            if (adResultsData.show_last_text == 1)
            {
                paginationHTML += "<li><a href='#' onclick='fetchResults(" + adResultsData.number_of_pages + ");'>last</a></li>";   
            }

            paginationHTML += "</ul>";
            paginationHTML += pageSpan.innerHTML = "<br>Page " + adResultsData.current_page + " of " + adResultsData.number_of_pages; 
        }

PHP

    $numberOfPages = $results['pages'];
$currentPage = $results['currentPage'];



if ($currentPage != 1 && $currentPage != 2)
{$showFirst = 1;}
else $showFirst = 0;

if ($currentPage != 1)
{$showPrevious = 1;}
else $showPrevious = 0;

if ($currentPage != $numberOfPages)
{$showNext = 1;}
else $showNext = 0;

if ($currentPage != $numberOfPages && $currentPage != ($numberOfPages - 1))
{$showLast = 1;}
else $showLast = 0;



if ($currentPage <= 5 && $numberOfPages <= 5 || $numberOfPages <= 5)
{$startingPage = 1;}
else if ($currentPage == 1 || $currentPage == 2)
{$startingPage = 1;}
else
{$startingPage = $currentPage - 2;}



$pageNumbers = [];
for ($i = $startingPage; $i < ($startingPage + 5) && $i <= $numberOfPages; $i++)
{
    $pageNumbers[] = $i;
}

$ pagesString = implode(“,”,$ pageNumbers); $ listingsString = implode(“,”,$ listingsArray);

$ jsonString =&lt;&lt;&lt;结束 {           “resultsTotal”:$ numberOfResults,               “listing”:[$ listingsString],        “number_of_pages”:$ numberOfPages,           “current_page”:$ currentPage,

谢谢!

0 个答案:

没有答案