I have this code in my javascript:
(function ($) {
Drupal.behaviors.myid_print_table_id_link = {
attach: function (context, settings) {
$.ajax({
type: 'POST',
url: '?q=myid_print/table_pager',
success: function(data) {
console.log(data);
}
}).done(function(o) {
console.log(o);
});
}
}
})(jQuery);
This calls a function called myid_print_table_pager
declared in my hook menu:
function myid_print_menu(){
$items = array();
$items['myid_print/table_pager'] = array(
'title' => 'Table Pager',
'page callback' => 'myid_print_table_pager',
'type' => MENU_CALLBACK,
);
return $items;
}
}
Below is my function:
function myid_print_table_pager(){
drupal_add_js('$(document).ready(function () { alert("Hello!"); });', 'inline');
watchdog('message', 'I've been here!');
}
I'm pretty sure that the function myid_print_table_pager
is invoke because 'I've been here!'
is seen in my watchdog
table in my database. But why does the alert with the message Hello!
has not been invoke?
drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');
$
is just an alias forjQuery
. Maybe it is overwritten.return array('#markup' => 'Hello world');
. I'm not sure if Drupal handles the page correctly if you don't provide the main page content.