@MutantMahesh
https://www.drupal.org/u/msankhala
// misc/ajax.js
Drupal.ajax = function (base, element, element_settings) {
var defaults = {
url: 'system/ajax',
event: 'mousedown',
keypress: true,
selector: '#' + base,
effect: 'none',
speed: 'none',
method: 'replaceWith',
progress: {
type: 'throbber',
message: Drupal.t('Please wait...')
},
submit: {
'js': true
}
};
...// misc/ajax.js
Drupal.ajax.prototype.commands = {
/**
* Command to remove a chunk from the page.
*/
remove: function (ajax, response, status) {
var settings = response.settings || ajax.settings || Drupal.settings;
Drupal.detachBehaviors($(response.selector), settings);
$(response.selector).remove();
},
...
}// includes/ajax.inc
function ajax_command_remove($selector) {
return array(
'command' => 'remove',
'selector' => $selector,
);
}
function ajax_command_append($selector, $html, $settings = NULL) {
return array(
'command' => 'insert',
'method' => 'append',
'selector' => $selector,
'data' => $html,
'settings' => $settings,
);
}$wrapper['link'] = array(
'#markup' => l(
t('Click me to load via ajax'),
'<some/drupal/internal/path>',
array(
'attributes' => array('class' => 'use-ajax'),
)
),
);
drupal_add_library('system', 'drupal.ajax');
// or
$wrapper['#attached']['library'] = array(
array('system', 'drupal.ajax')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#attributes' => ['class' => ['use-ajax-submit']],
);
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'jquery.form');
// or
$form['#attached']['library'] = array(
array('system', 'drupal.ajax')
);
$form['#attached']['library'] = array(
array('system', 'jquery.form')
);This path may contain '/nojs/' as part of the path.
'#ajax' => array(
'path' => 'some/drupal/path/nojs', // optional. default to 'system/ajax'.
// If specified, you must set up the menu entry
// and handle the entire callback
'callback' => 'ajax_response_callback',
'wrapper' => 'replace_textfield_div', // id of element to replace
'method' => 'replaceWith' // optional.
'effect' => 'fade', // optional
'event' => 'click', // optional
'prevent' => 'click', // optional
'progress' => array( // optional
'type' => 'bar',
'message' => 'Loading...',
'url' => '</url/returning/progress/and/message>',
'interval' => 1000
),
),function ajax_response_callback() {
$commands = array();
$commands[] = ajax_command_append('#selector', "Stuff...");
$commands[] = ajax_command_replace("#wrapper", "replaced content" );
return array('#type' => 'ajax', '#commands' => $commands);
}
// include/ajax.inc
function ajax_command_append($selector, $html, $settings = NULL) {
return array(
'command' => 'insert',
'method' => 'append',
'selector' => $selector,
'data' => $html,
'settings' => $settings,
);
}// core/misc/ajax.js
Drupal.AjaxCommands.prototype = {
remove: function (ajax, response, status) {
var settings = response.settings || ajax.settings || drupalSettings;
$(response.selector).each(function () {
Drupal.detachBehaviors(this, settings);
})
.remove();
},
...
}
// In Drupal 7 it was Drupal.ajax.prototype.commands = {...}Client side
Server Side