Ajax calls not properly queued I ran into this issue on my own plugin and then decided to download the Drupal Example Modules to discover the same issue was happening to me in the 'ajax_example' section.

Ajax calls don't seem to queue, and the last message sent to the server overrides the last.

This is the code I am using. (It can also be found in ajax_example.module.)

function ajax_example_autotextfields($form, &amp;$form_state) {
  $form['ask_first_name'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; t('Ask me my first name'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'ajax_example_autotextfields_callback',
      'wrapper' =&gt; 'textfields',
      'effect' =&gt; 'fade',
    ),
  );
  $form['ask_last_name'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; t('Ask me my last name'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'ajax_example_autotextfields_callback',
      'wrapper' =&gt; 'textfields',
      'effect' =&gt; 'fade',
    ),
  );
  $form['textfields'] = array(
    '#title' =&gt; t("Generated text fields for first and last name"),
    '#prefix' =&gt; '&lt;div id="textfields"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#type' =&gt; 'fieldset',
    '#description' =&gt; t('This is where we put automatically generated textfields'),
  );

  // Since checkboxes return TRUE or FALSE, we have to check that
  // $form_state has been filled as well as what it contains.
  if (!empty($form_state['values']['ask_first_name']) &amp;&amp; $form_state['values']['ask_first_name']) {
    $form['textfields']['first_name'] = array(
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('First Name'),
    );
  }
  if (!empty($form_state['values']['ask_last_name']) &amp;&amp; $form_state['values']['ask_last_name']) {
    $form['textfields']['last_name'] = array(
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('Last Name'),
    );
  }

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Click Me'),
  );

  return $form;
}

function ajax_example_autotextfields_callback($form, $form_state) {
  return $form['textfields'];
}


This is the screenshot of the page.


  


After selecting 'first name', 'second name' before 'first name' has time to finish loading.


  


The 'first name' field is never loaded. 

How can I fix this?
Drupal doesn't queue AJAX requests, no. If it's causing a problem, you might want to implement some JS to disable the form while a request takes place. 

Alternatively, as it doesn't appear your fields are required, you could use #states instead. They don't require an AJAX call, but (depending on your ultimate requirements of course) will give you the same effect as your current code.