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.
Controller:
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";
}
}
View:
$('#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;
});
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?
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().
Return a json object with two attributes:
Remember to encode quotes in the markup.