Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7444925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:41:36+00:00 2026-05-29T11:41:36+00:00

This problem is going to be a little harder to explain, so bear with

  • 0

This problem is going to be a little harder to explain, so bear with me. I have created ajax pagination for my application. Here is the core code for how it functions in the controller (some code is obviously changed or not shown for privacy concerns):

function action(){
    //PROBLEM LIES HERE
    if ($this->params['isAjax']){
        $page = $_COOKIE['page'];
    } else {
        $page = 1;
    }
    //END PROBLEM AREA
    $offset = ($page - 1) * $this->perPage;
    $limit = $this->perPage + 1; //+1 so we can test if there are more after
    setcookie('page', ++$page, 0, '/');

    $objects = $this->getObjects($query, $limit, $offset);
    $moreObjects = count($objects) > $this->perPage;
    $objects = array_slice($objects, 0, $this->perPage);
    $this->set('objects', $objects);

    if ($this->params['isAjax']){
        $this->set('type', 'objects');
        $rendered = $this->render('/elements/ajax_elements', null);
        echo json_encode(array('objects' => $rendered, 'moreObjects' => $moreObjects));
        $this->_stop();
}
$this->set('moreObjects', $moreObjects);
}

I have included the RequestHandler component. This code works mostly, the problem is that the AJAX request is not being set by CakePHP (v 1.3) after the second page. So consequently the the third page is the same page as the second page (duplicates), this happens since the $page gets set to 1 again. What is also weird, is that the following pages load fine. I have examined the HTTP requests, there is a clear difference between the AJAX requests and the non-AJAX requests and the second page loading problem request is most always a non-AJAX request. Even this code returns false on the second page:

function isAjax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest");
} 

Why is this happening? If you need me to provide any other information, let me know. I am happy to hear any suggestions, solutions and/or debugging ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:41:39+00:00Added an answer on May 29, 2026 at 11:41 am

    This doesn’t sound like a CakePHP issue, it sounds like the headers that your browser is sending with the request.

    I would recommend using a request inspection tool, like Fiddler (http://fiddler2.com/fiddler2/). This will let you inspect the headers and the requests and responses from all of your calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have this really weird problem in a Web Application when using ActiveRecord 2.0
I've been going at this problem for a solid couple hours now and having
This problem has been kicking my butt for a few days now. I have
This problem has bugged me so many times and i have now decided to
This is the problem. I'm working on a little Java tool which is composed
Going through a weird problem here. I am trying to get the date of
Ok I was a little unsure on how best name this problem :) But
So I'm getting experience on this stuff little by little, but this problem seems
Okay, for whatever reason I can't seem to figure this little problem out. I
I'm going crazy with this my little app... Please help me!!! this is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.