I want on onclick event send some data to module and do some processing and get result back.
I have module name ‘custom’ and js code i have mentioned below. Url of page from where ajax call is made is 127.0.0.1/field-work
Drupal.behaviors.custom = function (context, settings)
{
$(document).on('click', '#clear-filter', function() {
console.log("Hello");
jQuery.ajax({
type: 'POST',
url: 'custom/field-work',
dataType: 'json',
success: function(data){
console.log(data);
},
});
});
};
Module code to receive ajax call have mentioned below.
function custom_menu() {
$items['custom/field-work'] = array(
'title' => t('foo AJAX'),
'type' => MENU_CALLBACK,
'page callback' => 'details_data',
'access arguments' => array('access content'),
);
return $items;
}
From details_data i am returning some random data. But ajax call is not working. If i am removing drupal behaviour the js part is working fine.
Please help me out.