Drupal - Manually invoking Ajax Commands when an ajax callback is not an #ajax form callback

Like @Gaius I don't know exactly what @Jaypan wants to achieve. This example might help to make this clearer:

        var response = JSON.parse(content);
        // Create a Drupal.Ajax object without associating an element, a
        // progress indicator or a URL.
        var ajaxObject = Drupal.ajax({
          url: '',
          base: false,
          element: false,
          progress: false
        });
        // Then, simulate an AJAX response having arrived, and let the Ajax
        // system handle it.
        ajaxObject.success(response, 'success');

Normally you set an URL in Drupal.ajax() and then use ajaxObject.execute() to run the Ajax request. This example from big_pipe.js only simulates the Ajax request and then runs the Ajax commands contained in content.


It might not be related and is also a rather old post, but for anybody like myself desperately searching for some hint on the Drupal 8 ajax api:

Drupal.ajax({url: '/some/url'}).execute().done(
    function(comands, statusString, ajaxObject){
        console.log("we're done ;-)");
})

This tutorial might also be helpfull: https://www.thirdandgrove.com/rendering-view-ajax-drupal-8

Tags:

Ajax

8