Sometimes you need a snippet to display the drupal messages (drupal_set_message) created messages after an ajax call as result (for example if a node was created via ajax).
The following snippet removes old messages from the site and appends new messages in the AJAX callback:
function ..._ajax_callback(){
$commands = array();
$commands[] = ajax_command_remove('div.messages');
$commands[] = ajax_command_after('#your-container-id', theme('status_messages'));
return array('#type' => 'ajax', '#commands' => $commands);
}
?>
This snippet was inspired by this discussion:
https://www.drupal.org/node/1028410