title: unable to show success message after submitting a form using ajax
body: <p>I am sending email using ajax after when ajax form is submitted.</p>
  
  <p>Here is my php controller code:
  If i keep the email sending code inside this function then the <code>SUCCESS</code> message is not showing on the html page. But if i remove the <code>Email sending</code> code from that function then <code>SUCCESS</code> message is showing.</p>
  
  <pre><code>public function  sendedits()
     {
       $this-&gt;load-&gt;library('form_validation');
       $this-&gt;form_validation-&gt;set_error_delimiters('&lt;li  class="errorlist"&gt;', '&lt;/li&gt;')-&gt;set_rules('menu_name', 'Title', 'trim|required|min_length[2]|max_length[255]|xss_clean');
  
          //user is logged in proceed the next work
             if (!$this-&gt;form_validation-&gt;run()) 
             {   //False  
                 $this-&gt;_status['status'] = "error";
                 $this-&gt;_status['message'] = $this-&gt;load-&gt;view('commonfiles/ajax_error_display_1', '', TRUE);
             } 
  
              else if ($this-&gt;form_validation-&gt;run() &amp;&amp; $this-&gt;input-&gt;post('myId')=='')//myId=just for checking robot or human
               {      //TRUE block   
                $fname=$this-&gt;input-&gt;post('menu_name');
                $sendersemail=$this-&gt;input-&gt;post('changes_made');     
                $intrested_message=$this-&gt;input-&gt;post('content');   
                 $config['protocol'] = 'smtp';
                 $config['smtp_host'] = 'ssl://smtp.googlemail.com';
                 $config['smtp_port'] = 465;
                 $config['smtp_user'] = 'asdsdsd@gmail.com';
                 $config['smtp_pass'] = 'sdsfsdfsdfsdfsds'; 
                 $this-&gt;load-&gt;library('email', $config);
                 $this-&gt;email-&gt;set_newline("\r\n"); 
                 //$this-&gt;email-&gt;from($sendersemail, $fname);
                 $this-&gt;email-&gt;to('ssdd@myemil.com');     
                      $this-&gt;email-&gt;subject('User Edited article of : '.$fname); 
                     $message = '&lt;html&gt;
                                         &lt;head&gt;
                                             &lt;title&gt;&lt;/title&gt;
                                             &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
                                         &lt;/head&gt;
                                         &lt;body&gt;
                                          &lt;table cellspacing="0" cellpadding="0" style="border-collapse:collapse;width:98%;background-color:whitesmoke" border="1"&gt;
                                              &lt;tbody&gt;
                                                  &lt;tr&gt;
                                                         &lt;td colspan=2&gt;&lt;h2&gt; '.$fname.'&lt;/h2&gt;&lt;/td&gt;
                                                  &lt;/tr&gt;  
                                                  &lt;tr&gt;
                                                       &lt;td width=50%&gt;First  Name &lt;/td&gt;
                                                        &lt;td width=50%&gt;'.$fname.'&lt;/td&gt;
                                                 &lt;/tr&gt;      
                                                 &lt;tr&gt;
                                                       &lt;td width=50%&gt;Email &lt;/td&gt;
                                                        &lt;td width=50%&gt;'.$sendersemail.'&lt;/td&gt;
                                                 &lt;/tr&gt;     
  
                                                      &lt;tr&gt;
                                                       &lt;td width=50%&gt;Message &lt;/td&gt;
                                                        &lt;td width=50%&gt;'.$intrested_message.'&lt;/td&gt;
                                                 &lt;/tr&gt;   &lt;/tbody&gt; &lt;table&gt; &lt;/body&gt;&lt;/html&gt;  ';
                 $this-&gt;email-&gt;message($message); 
                 $this-&gt;email-&gt;send(); 
                $this-&gt;_status['message'] = 'Thankyou for your edits. We will review it before publishing.'; 
                 $this-&gt;_status['status'] = "success"; 
               } 
            echo json_encode($this-&gt;_status);    
     } 
  </code></pre>
  
  <p>Ajax function for submitting the form</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
      $(document).ready(function() {
  
          var _status = $('#status');
          $('#sub2').click(function(e) {
  
              _status.html('');
              var postData = $('#form_id').serializeArray();
              var formURL = $('#form_id').attr("action");
              $.ajax({
                  url: formURL,
                  type: "POST",
                  data: postData,
                  dataType: "json",
                  success: function(dat) {
                      if (dat.status === 'success') { 
                          _status.html('&lt;span class="success"&gt;' + dat.message + '&lt;/span&gt;');
                      }
                      else if (dat.status === 'fail') {
  
                      }
                      else
                      {
  
                          _status.html('&lt;span class="err"&gt;' + dat.message + '&lt;/span&gt;');
  
                      }
                  },
                  error: function(e) {
                      alert("Ooops! Try again later or else sends us  message regarding this issue. Thankyou!");
                  }
              });
  
          });
  
      });
  
  &lt;/script&gt;
  </code></pre>