Drupal & AJAXified links: hook into requests before they are sent? I've got a link 'test/nojs' on a page. I've added the class 'use-ajax' to that link, so that Drupal automatically AJAXifies the link and replaces the 'nojs' part with 'ajax'. So far so good.

However, I'd like to hook into the AJAX request as there might be cases where I'd like to stop the request from being sent off to the server. However, I can't get it up and running properly.

One post say that I can do this by setting a 'hook' function in Drupal.ajax[element].beforeSend(a,b) and some places say that I can do it by settings a 'hook' function in Drupal.ajax[element].options.beforeSend(a,b). However, I can't get any of this to work. 

Is there a "right" way of hooking into the AJAX process? Even better, is there a "right" way of hooking into the AJAX process for certain elements?
You can use the following code,

Drupal.ajax[element].default_beforeSend = Drupal.ajax[element].beforeSend;
Drupal.ajax[element].beforeSend = function(xmlhttprequest, options) {
  if (1) {
    xmlhttprequest.abort();
  }
  else {
    Drupal.ajax[element].default_beforeSend(xmlhttprequest, options);
  }
}