diff --git includes/ajax.inc includes/ajax.inc
index 7eab334..6f98859 100644
--- includes/ajax.inc
+++ includes/ajax.inc
@@ -200,6 +200,7 @@ function ajax_get_form() {
  */
 function ajax_form_callback() {
   list($form, $form_state, $form_id, $form_build_id) = ajax_get_form();
+  $triggering_element_name = !empty($_POST['ajax_triggering_element']) ? $_POST['ajax_triggering_element'] : NULL;
 
   // Build, validate and if possible, submit the form.
   drupal_process_form($form_id, $form, $form_state);
@@ -208,9 +209,25 @@ function ajax_form_callback() {
   // drupal_process_form() set up.
   $form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
 
-  // Get the callback function from the clicked button.
-  $ajax = $form_state['clicked_button']['#ajax'];
-  $callback = $ajax['callback'];
+  // Find the triggering element. If it's NULL, then it's a submit and we already
+  // have the element available to us in $form_state['clicked_button'].
+  // Otherwise, we have to traverse the name to find the element using the name
+  // of the element we were given.
+  if (empty($triggering_element_name)) {
+    $triggering_element = $form_state['clicked_button'];
+  }
+  else {
+    $triggering_element = $form;
+    foreach (preg_split('/[\[\]]+/',$triggering_element_name) as $element) {
+      if (!empty($triggering_element[$element])) {
+        $triggering_element = $triggering_element[$element];
+      }
+    }
+  }
+  // Now that we have the element, get a callback if there is one.
+  if (!empty($triggering_element['#ajax']['callback'])) {
+    $callback = $triggering_element['#ajax']['callback'];
+  }
   if (drupal_function_exists($callback)) {
     $html = $callback($form, $form_state);
 
diff --git misc/ajax.js misc/ajax.js
index 0804992..02f2e59 100644
--- misc/ajax.js
+++ misc/ajax.js
@@ -96,7 +96,7 @@ Drupal.ajax = function (base, element, element_settings) {
       type: 'bar',
       message: 'Please wait...'
     },
-    button: {},
+    button: {}
   };
 
   $.extend(this, defaults, element_settings);
@@ -143,6 +143,9 @@ Drupal.ajax = function (base, element, element_settings) {
   // Bind the ajaxSubmit function to the element event.
   $(this.element).bind(element_settings.event, function () {
     if (ajax.form) {
+      if (element.type != 'submit') {
+        ajax.form.append('<input type="hidden" name="ajax_triggering_element" value="' + element.name + '" />');
+      }
       // If setClick is set, we must set this to ensure that the button's
       // value is passed.
       if (ajax.setClick) {
