Ajax error on dependent dropdown. Drupal 7
You need to remove the line

'#options' =&gt; _ajax_example_get_second_dropdown_options($selected),


Then, put your function call and update the #options on some condition. So, something like this:

if(isset($form_state['values']['first_select_box'])) {
  if($form_state['values']['first_select_box'] == 'something'){
    //the contents of your _ajax_example_get_second_dropdown_options function here
    //and instead of returning something... just SET #options to your new output.
    $form['second_select_box']['#options'] = 'new stuff';
  }
}


Furthermore, most of the time people will not even show the second select box until the first one is filled out with something useful for the second. In that case, you can set the #type of the second select box to 'markup' and then in that above if statement SET the #type to select.

$form['second_select_box'] = array(
  '#type' =&gt; 'markup',
  '#prefix' =&gt; '&lt;div id="second-select-box-replace"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
);

if(isset($form_state['values']['first_select_box'])) {
  if($form_state['values']['first_select_box'] == 'something'){
    //the contents of your _ajax_example_get_second_dropdown_options function here
    //and instead of returning something... just SET #options to your new output.
    $form['second_select_box']['#type'] = 'select';        
    $form['second_select_box']['#options'] = 'new stuff';
    $form['second_select_box']['#title'] =&gt; 'Choose';
  }
}