title: Codeigniter session flashdata and ajax
body: <p>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?</p>
  
  <p>This is, what my function looks like:</p>
  
  <pre><code>public static function message()
  {
      if ( ! empty(self::$message['message']))
      {
          // build message
          $message = '&lt;div class="alert alert-' . self::$message['type'] . '"&gt;&lt;button type="button" class="close" data-dismiss="alert"&gt;&amp;times;&lt;/button&gt;&lt;strong&gt;' . self::$message['heading'] . '&lt;/strong&gt;' . self::$message['message'] . '&lt;/div&gt;';
  
          // clear static message array
          self::$message = array();
  
          // return static message
          return $message;
      }
      else
      {
          if ( class_exists('CI_Session'))
          {
              // get flash message
              $message = self::$CI-&gt;session-&gt;flashdata('message');
  
              // clear flash data
              self::$CI-&gt;session-&gt;set_flashdata('message', null);
  
              // process flash message
              if ( ! empty($message))
              {
                  // slice flashdata into single parts
                  $message = explode('::', $message);
  
                  // return flash message
                  return '&lt;div class="alert alert-' . $message[0] . '"&gt;&lt;button type="button" class="close" data-dismiss="alert"&gt;&amp;times;&lt;/button&gt;&lt;strong&gt;' . $message[1] . '&lt;/strong&gt;' . $message[2] . '&lt;/div&gt;';
              }
          }
      }
  
      return '';
  }
  </code></pre>