title: jQuery AJAX return the function as data upon success
body: <p>I have codeigniter flashdata + jQuery AJAX call to show it. the code:</p>
  
  <pre><code>&lt;script type="application/javascript"&gt;
  
  var res_no = '&lt;?php echo $this-&gt;session-&gt;flashdata('res_no'); ?&gt;';
  var res_new = '&lt;?php echo $this-&gt;session-&gt;flashdata('res_new'); ?&gt;';
  
  (function( $ ) {
  
  $("#check-reservations").click(function() {
  
     $.ajax({
              type: "POST",
              url: "mycontroller/function",
              async: true,
              data: {
              res_no: res_no,
              res_new: res_new
              },
              success: function(data) {   
              if(data) {
              alert(data);
              }
             }
          });
       });
  
  /*
  Default Notifications
  */
  $('#check-reservations').show(function() {
  
      if (res_no) {
      new PNotify({
          title: 'Hmm no new Reservations..',
          text: res_no,
          type: 'custom',
          addclass: 'notification-primary',
          icon: 'fa fa-info-circle '
      });
      }
  
      else if (res_new) {
      new PNotify({
          title: 'There\'s something new!',
          text: res_new,
          type: 'custom',
          addclass: 'notification-success',
          icon: 'fa fa-check'
      });
      }
     });
     }).apply( this, [ jQuery ]);
   &lt;/script&gt;
  </code></pre>
  
  <p>inside the $.ajax data, i have added both </p>
  
  <pre><code>res_no: res_no,
  res_new: res_new
  </code></pre>
  
  <p>which are just strings with text, upon success I retrive back alert with text. I want to get back the </p>
  
  <pre><code>new PNotify({
          title: 'Hmm no new Reservations..',
          text: res_no,
          type: 'custom',
          addclass: 'notification-primary',
          icon: 'fa fa-info-circle '
      });
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code> /**
      * @filtered_reservations
      * @index
      */
      $filtered_reservations = $this-&gt;filter_array($reservations);          
      if (count($filtered_reservations) &gt; 0) {
      foreach ($filtered_reservations as $index =&gt; $reservation) {
      $this-&gt;db-&gt;insert('reservations', $reservation);   
      } // end foreach   
      return $this-&gt;session-&gt;set_flashdata('res_new', "Success ". count($filtered_reservations) ." Reservations were Inserted!"); 
      print "Success ". count($filtered_reservations) ." Reservations were Inserted!";
      print "Reservations: ". count($kigores_id) ." found on kigo!";
      } /* end if */
  
  
      /**
      * @filtered_reservations
      * equal to 0
      */
      elseif (count($filtered_reservations) === 0) {
      print "Sorry no new Reservations!";
      return $this-&gt;session-&gt;set_flashdata('res_no', 'Sorry no new Reservations!');
      //$this-&gt;ci_alerts-&gt;set('warning', "Sorry no new Reservations!");
      }
  
      } /* end reservations */     
  </code></pre>
  
  <p>What should I write in the data? Only solution I found so far is the window.reload which will show me the notification like I want but with refresh.. </p>