Deliver ajax commands on successful form submit
You return the ajax commands in your ajax callback function.

function my_module_form_ajax_submit(array $form, array &amp;$form_state){
  if (count(form_get_errors())) {
    return array(
      'track_id' =&gt; $form['track_id'],
      'courier' =&gt; $form['courier'],
    );
  }
  else {
    $ajax_commands = array();
    $ajax_commands[] = ajax_command_invoke('myModal', 'modal', array('hide'));
    $ajax_commands[] = ajax_command_replace('form-finished-wrapper-'.$node-&gt;nid, t('Submited Successfuly'));
    return array('#type' =&gt; 'ajax', '#commands' =&gt; $ajax_commands);
  }
}


I'm not sure what you were trying to do with your original callback, so I couldn't incorporate it.