Dynamic select lists (dependent dropdowns) I created 2 dependent dropdowns in Drupal 7. In the first dropdown you need to choose the device, in order to see its attributes in the second dropdown. 

When an option from the first list is selected, the Ajax throbber appears but it doesn't seem to be working and I don't get the appropriate options in the second dropdown.

I have read all examples and resources I could find online, but I haven't found how to fix this. Any help would be very much appreciated. 

Below I attach the relevant code. Apologies in advance, I am new in Drupal.

function my_module_getdevicesfromrooms() {
  $dropdown1 = array();

  $tabdelimited = file_get_contents("http://.../tabdelimited");

  // some code
  return $dropdown1;
}

/**
 * The device name is required in order to get the attributes using this function
 */
function my_module_getattributesfromdevices($test) {
  $dropdown2 = array();
  $tabdelimited = file_get_contents("http://....");
  // some code

  return $dropdown2;
}

function my_module_form_ajax($form, &amp;$form_state) {
  $form['#prefix'] = "&lt;div id='latest-div'&gt;";
  $form['#suffix'] = "&lt;/div&gt;";   
  $options_first = my_module_getdevicesfromrooms();
  $value_dropdown_first = isset($form_state['values']['my_module_deviceurn']) ? $form_state['values']['my_module_deviceurn'] : $options_first;

  $state2 = my_module_getattributedfromdevices($value_dropdown_first); 

  $form['my_module_deviceurn'] = array(
    '#type' =&gt; 'select', 
    '#title' =&gt; 'Device', 
    '#options' =&gt; $options_first, 
    '#default_value' =&gt; $value_dropdown_first,
  );

  $form['my_module_apply'] = array(
    '#type' =&gt; 'button',
    '#title' =&gt; t('Apply'),
    '#default_value' =&gt; t('apply'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'my_module_ajax_callback',
      'wrapper' =&gt; 'nodes-div',
      'method' =&gt; 'replace',
      'effect' =&gt; 'fade',
    ),
  );

  $form['my_module_attributes'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Attributes'),
    '#options' =&gt; $state2,
    '#default_value' =&gt; variable_get('my_module_attributes', ''),
  );
  return $form;
}

function my_module_ajax_callback($form, $form_state) {
  return $form;
}
On your callback function, you need to setup a callback help. Basically getting your form data. Now my code is for D6 so some functions might be slightly different but check this out.
I left some of my tweaks in there. You'll just have to adjust accordingly.  but the big thing is the callback helper function.

function MOD_js_callback() {

// use of ajax callback helper to set form variables again
$form = MOD_callback_helper();

// grab form['datacenter_devices'] data and drop into changed_elements
// simply to not confuse rebuilt form with 'global' form
$changed_elements = $form['datacenter_devices'];

// Prevent duplicate wrappers.
unset($changed_elements['#prefix'], $changed_elements['#suffix']);

// concat status_messages and call drupal_render to render elements array for output.
$output = theme('status_messages') . drupal_render($changed_elements);
drupal_json(array(
    'status'   =&gt; TRUE,
    'data'     =&gt; $output,
));
}
function MOD_callback_helper() {

$form_state = array('storage' =&gt; NULL,'submitted' =&gt; FALSE);

$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
// Enable the submit/validate handlers to determine whether AHAH-submittted.
$form_state['ahah_submission'] = TRUE;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);

$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

return $form;
}