Codeigniter session flashdata and ajax

I'm using codeigniter flashdata to set messages after a redirect. Well if I'm using it without ajax, everything just works fine. If I echo out messages received with flashdata it still works like it should BUT if I refresh with F5 once, I still see that message. Flashdata gets cleared after the second refresh... How can I resolve this?

This is, what my function looks like:

public static function message()
    if ( ! empty(self::$message['message']))
        // build message
        $message = '<div class="alert alert-' . self::$message['type'] . '"><button type="button" class="close" data-dismiss="alert">&times;</button><strong>' . self::$message['heading'] . '</strong>' . self::$message['message'] . '</div>';

        // clear static message array
        self::$message = array();

        // return static message
        return $message;
        if ( class_exists('CI_Session'))
            // get flash message
            $message = self::$CI->session->flashdata('message');

            // clear flash data
            self::$CI->session->set_flashdata('message', null);

            // process flash message
            if ( ! empty($message))
                // slice flashdata into single parts
                $message = explode('::', $message);

                // return flash message
                return '<div class="alert alert-' . $message[0] . '"><button type="button" class="close" data-dismiss="alert">&times;</button><strong>' . $message[1] . '</strong>' . $message[2] . '</div>';

    return '';


Form the CI Manual:

If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.


So you need to modify your AJAX handling method to keep the items you need.

Need Your Help

The action 'like' could not be found for TodoController

ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-3.2

I'm trying to add a like link to my first app, and I get this error: "The action 'like' could not be found for TodoController"

Transactions spanning multiple schemas in a database

java oracle

I have a single connection which does DML on objects in two different schemas of an Oracle database. I complete a transaction involving objects in schema A and then start a second transaction to w...