ajaxify content via a callback function I am trying to ajaxify my site. I want the "Main page content" to be passed via an ajax-command to a custom js-function.  

To accomplish this I would do the following:


I need to register a path for my ajax requests


code:

$items['_custom_ajax_'] = array(
  'title' =&gt; 'AHAH callback',
  'page callback' =&gt; 'ajax_form_callback',
  'delivery callback' =&gt; '_custom_ajax_deliver',
  'access callback' =&gt; TRUE,
  'theme callback' =&gt; 'ajax_base_page_theme',
  'type' =&gt; MENU_CALLBACK,
);



use a custom delivery callback function _custom_ajax_deliver which is the copy of the ajax_deliver()


original code:

function ajax_deliver($page_callback_result) {
  // Browsers do not allow JavaScript to read the contents of a user's local
  // files. To work around that, the jQuery Form plugin submits forms containing
  // a file input element to an IFRAME, instead of using XHR. Browsers do not
  // normally expect JSON strings as content within an IFRAME, so the response
  // must be customized accordingly.
  // @see http://malsup.com/jquery/form/#file-upload
  // @see Drupal.ajax.prototype.beforeSend()
  $iframe_upload = !empty($_POST['ajax_iframe_upload']);

  // Emit a Content-Type HTTP header if none has been added by the page callback
  // or by a wrapping delivery callback.
  if (is_null(drupal_get_http_header('Content-Type'))) {
    if (!$iframe_upload) {
      // Standard JSON can be returned to a browser's XHR object, and to
      // non-browser user agents.
      // @see http://www.ietf.org/rfc/rfc4627.txt?number=4627
      drupal_add_http_header('Content-Type', 'application/json; charset=utf-8');
    }
    else {
      // Browser IFRAMEs expect HTML. With most other content types, Internet
      // Explorer presents the user with a download prompt.
      drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
    }
  }

  // Print the response.
  $commands = ajax_prepare_response($page_callback_result);
  $json = ajax_render($commands);
  if (!$iframe_upload) {
    // Standard JSON can be returned to a browser's XHR object, and to
    // non-browser user agents.
    print $json;
  }
  else {
    // Browser IFRAMEs expect HTML. Browser extensions, such as Linkification
    // and Skype's Browser Highlighter, convert URLs, phone numbers, etc. into
    // links. This corrupts the JSON response. Protect the integrity of the
    // JSON data by making it the value of a textarea.
    // @see http://malsup.com/jquery/form/#file-upload
    // @see http://drupal.org/node/1009382
    print '&lt;textarea&gt;' . $json . '&lt;/textarea&gt;';
  }

  // Perform end-of-request tasks.
  ajax_footer();
}



create an custom function which do the ajax request like Drupal.ajax
bind the ajax request to some selector e.g. a.ajaxify
add a custom ajax-command


Im not sure if this is the right way, or if I can extend the core easier somehow.
Basicly my approach is simmilar  to the module Ajaxify Drupal with JQuery Ajax

Better Ideas?

Update: one more thing – I need an event to be triggered everytime an ajax-link is clicked.
IMHO, I'd like to use Drupal AJAX API instead of jQuery AJAX because it supports many commands, events and content are manageable, error control and event binding for new content, those features are supported by Drupal.

But the disadvantage is it sends too much data, process is more complicated, using POST all the times. But of course, at javascript level, we can override the default behaviors and make it better :)

For example, If you have any ajax errors, like ajax request is running and you change document location, you will see an alert box with error message. That's a bit annoying so I always override it by re-write this function in my theme

Drupal.ajax.prototype.error


About your working process, I have some comments


1 &amp; 2: It's ok for me, but why do you need to use another copy of ajax_deliver(), why don't you use it directly?
3: Are you going to write another thing like Drupal.ajax or just attach new function to Drupal.ajax? something like 

Drupal.ajax.prototype.commands.log = function (ajax, response) {
    console.log(response);
};

Drupal.ajax.prototype.commands.open_popup = function (ajax, response) {
    var id      = typeof response.id      === 'string' ? response.id : 'gfc';
    var content = typeof response.content === 'string' ? response.content : '';
    var options = typeof response.options === 'object' ? response.options : {};

    Gfc.popup.open(id, content, options);
};


I'm ok if you do like that.
4: Yes of course
5: Errr, are you going to write something new instead if using Drupal.ajax?