drupal_add_js within AJAX callback
drupal_add_js doesn't work properly in an AJAX callback. If you need to execute a JavaScript function within an AJAX callback, here's a way :

First, in your form, you have to create (you can just import it) the JavaScript function :

function my_module_form($form, &amp;$form_state) {
// [...]
  drupal_add_js(
    'Drupal.ajax.prototype.commands.myFunction = function(ajax, response, status) {
      // Whatever you want to do.
    }',
    'inline'
  );
// [...]
  return $form;
}


Then, in your AJAX callback, you need to call this function you created :

function my_module_my_ajax_callback($form, &amp;$form_state) {
// [...]
  $commands[] = array("command" =&gt; 'myFunction',);
// [...]
  return array('#type' =&gt; 'ajax', '#commands' =&gt; $commands);
}


Hope it helps !