Document AJAX no-js and use-ajax

Created on 20 October 2009, almost 15 years ago
Updated 29 July 2024, about 1 month ago

I've been playing with the new ajax framework and have successfully used it for the admin form on the D7 version of Quicktabs - awesome stuff, the ajax callback is so simple! :-)
Anyway, I was also testing the use of the 'use-ajax' class to do just a regular ajax request when clicking on a link. My menu callback calls ajax_deliver() as long as ajax is passed in and not nojs. I can get this to work only by hacking ajax.js to tell it what element.wrapper and element.click should be, otherwise it causes a js error as these properties are missing and I can't figure out how to set them from the php side. I, perhaps naively, thought that something like this should work:

  $build['ajaxy_link'] = array(
    '#type' => 'link',
    '#title' => t('Click here'),
    '#href' => 'ajaxy/nojs/',
    '#attributes' => array('class' => array('use-ajax')),
    '#ajax' => array(
      'event' => 'click',
      'wrapper' => 'content',
    ),
  );

Anyway, this does not load ajax.js on the page and does not communicate the wrapper and event properties as required. It would be great if someone who understands how this should work could either add the explanation to the existing docs or give a brief instruction in this thread and I'll write it up in the docs.

📌 Task
Status

Fixed

Version

7.0 ⚰️

Component
Documentation 

Last updated 1 minute ago

No maintainer
Created by

🇨🇦Canada katbailey

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone New Zealand

    This was committed to Drupal 7 in 2010 and re-opened with a question about Drupal 7. Shortly after the version was changed to Drupal 8. Then the file ajax.inc was removed from Drupal 8, 📌 Remove ajax.inc Fixed and documentation updated. Therefor I am closing this as outdated.

  • Status changed to Fixed about 2 months ago
  • 🇳🇿New Zealand quietone New Zealand

    Actually, credit should be given to those who fixed the issue in D7. Changing status and version.

    If there is anything here that needs to be done on D11.x, open a new issue.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024