Drupal 8  8.0.2
/var/www/d8/core/misc/ajax.js

Provides Ajax page updating via jQuery $.ajax.

This function is designed to improve developer experience by wrapping the initialization of Drupal.Ajax objects and storing all created objects in the Drupal.ajax.instances array.

Drupal.behaviors.myCustomAJAXStuff = { attach: function (context, settings) {

var ajaxSettings = { url: 'my/url/path', // If the old version of Drupal.ajax() needs to be used those // properties can be added base: 'myBase', element: .find('.someElement') };

var myAjaxObject = Drupal.ajax(ajaxSettings);

// Declare a new Ajax command specifically for this Ajax object. myAjaxObject.commands.insert = function (ajax, response, status) { $('#my-wrapper').append(response.data); alert('New content was appended to #my-wrapper'); };

// This command will remove this Ajax object from the page. myAjaxObject.commands.destroyObject = function (ajax, response, status) { Drupal.ajax.instances[this.instanceIndex] = null; };

// Programmatically trigger the Ajax request. myAjaxObject.execute(); } };

Parameters
{object}settings The settings object passed to Drupal.Ajax constructor.
{string}[settings.base] Base is passed to Drupal.Ajax constructor as the 'base' parameter.
{HTMLElement}[settings.element] Element parameter of Drupal.Ajax constructor, element on which event listeners will be bound.
Returns
{Drupal.Ajax}
See Also
Drupal.AjaxCommands