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 954079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:09:16+00:00 2026-05-16T00:09:16+00:00

Basically it breaks down like this: A master template page is loaded when one

  • 0

Basically it breaks down like this:

  • A master template page is loaded when one visits the application.
  • Links are handled by an onclick handler, which reload relevant portions of the master via a jQuery ajax call, trigger other events, etc.
  • After the initial onclick handler completes, it then calls two or more ajax callbacks which update other portions of the page.

The problem:

  • The final callback reads CakePHP’s flash message command $session->flash(), and displays the result in a simple javascript popup, who’s div tag is created via $(‘body’).prepend(). Once the popup is closed, the element that was created is .remove()’ed from the DOM.
  • When the user clicks a link and the flash message callback is ran for the next page, the CakePHP flash message data never got deleted, and it redisplays the message. This will repeat anywhere from 2-5 times as one continues to click pages, or until a little time has passed, and then finally delete the message from the PHP session.
  • When visiting the ajax link directly, the flash data is displayed once, and then deleted after the page is reloaded.

This has been boggling my mind for the last week. I’ve trimmed out every other unrelated thing except the callback itself, and it still displays the same behavior. Frustrating.

The code is quite simple, and looks like so:

The layout page which gets handed back after an onclick call.

<?php echo $content_for_layout ?>

<script>
  $(window).ready(function() {
    page_load_callback();
  });
</script>

The javascript.

function page_load_callback() {

  $.ajaxSetup({
        cache: true // We want our client to cache stuff, and override this in PHP.
  });

  $.ajax({
        cache: false, // Force this to not cache via jQuery
        beforeSend: function() {
            $('body').prepend('<div id="flash_message_popup"></div>');
        },
        url: flash_message_popup_link, // global variable set in default.ctp
        success: function(data) {
            $('#flash_message_popup').html(data);
            if ($('#flash_message_popup').is(':empty')) {
                $('#flash_message_popup').remove();
            } else {
                create_popup('flash_message_popup');
            }
        },
        error: function(a, b, c) {
            $('#flash_message_popup').remove();
        }
    });
}

function create_popup(tag) {
    if (editing_hall == true) {
        return false;
    }
    var selector = '#' + tag;
    $(selector).attr('style', 'position: absolute; display: none; top: 5; left: 5; z-index: 100;');
    $(selector).slideDown('slow');
}

The *.ctp file.

<?php if ($message = $session->flash()): ?>
<span id="flash_data">
    <div class="flash_message"><?php echo $message; ?></div>
    <div class="btn_large bottom_round"><a name="" onclick="$('#flash_message_popup').slideUp('slow', function() { $('#flash_message_popup').remove(); });">close</a></div>
</span>
<?php endif; ?>

The controller method.

function flash_message_popup() {
    $expires = 60*60*24*30*7;
    header('Expires: '.gmdate('D, d M Y H:i:s', time()-$expires) . ' JST'); // minus for past  
    $this->layout = 'ajax';

    $this->render('../elements/flash_message_popup');
}

Sessions get stored in a database, and haven’t proven to be a problem up until this specific instance. I’m not sure if this is a browser caching problem (I shouldn’t be? I am specifically not caching via both PHP and jQuery), a quirky session problem, a timing issue, something going haywire in my javascript, or what. I’ve tried adding a redundant callback which deletes the session in question with $this->Session->delete(‘Messages.flash’); with no luck as well.

If anyone has any advice I’d love to hear it. I am plum out of ideas.

Edit: I’ve also checked the Apache logs, and the callback is definitely getting called by the ajax query, but not deleting the session message. Only after I manually call it does it delete.

  • 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-16T00:09:17+00:00Added an answer on May 16, 2026 at 12:09 am

    The problem appears to be too many AJAX requests conflicting with database sessions, so the timing is completely off, and the database data seems to be getting overwritten with older session data. I will leave it at that and close this question.

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

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

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.