title: Return data and success/error message via AJAX
body: <p>I am creating some functionality whereby upon submitting a form, a success message is displayed and the updated details are fetched and displayed on the page, via AJAX.</p>
  
  <p>Controller:</p>
  
  <pre><code>public function updateAction()
  {
      $query="my query"
  
      if(mysql_query($query))
      {
          echo "Your changes have been saved successfully";
  
          $customer=Customer::getDetails($_POST['cust_id']);
  
          include('application/view/admin/customer/_view.php');
      }
      else
      {
          echo "There was a problem saving your changes";
      }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>$('#update-customer-form').submit(function(){
      $.ajax({
          url: 'admin/customer/update',
          type: 'POST',
          data: $(this).serialize(),
          success: function(result){
              alert(result);
              $('#details').html(result);
          }
      });
  
      return false;
  });
  </code></pre>
  
  <p>What I want to do is pass the success message, as well as the HTML output from the _view.php file if the record is saved successfully. Otherwise, just an error message is displayed. How can I do this?</p>
  
  <p>EDIT: Is there any way to do this other than using json_encode()? The problem I am having is including the PHP file in my json_encode().</p>