By stomerfull on
Hello
I have a custom module with these implemenation :
the hook menu :
$items['getdetail'] = array(
'title' => 'title',
'page callback' => 'get_detail',
'access callback' => TRUE,
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
my simple function (not a ajax callback)
function get_detail() {
drupal_add_library('system', 'drupal.ajax');
$commands = array();
$commands[] = ajax_command_alert("Aucun resultat");
return array('#type' => 'ajax', '#commands' => $commands);
}
I have a list in table an tr
echo "<tr><td height=30'><input type='checkbox'/></td><td width=250 onmouseover='showDetail(".$val['nid'].");'>".$val['name'].""</td></tr>";
and my js that call the function
function showDetail(nid) {
jQuery.ajax({
type: "POST",
url: "getdetail",
data: "nid="+nid,
success: function(data) {
}
});
}
but alert (ajax_command_alert) is not working
What is wrong in my code ?
Thank you very much for your help
Comments
Firstly, I'm not an expert,
Firstly, I'm not an expert, but I have a feeling it's because commands need to be done through Drupal.ajax, of which you need to create a new instance of. Commands are called in the /includes/ajax.js file via the Drupal.ajax.prototype.commands object, perhaps you could call that directly? Though by not using Drupal.ajax properly you won't be updating CSS and JS in your page callback if you decide to add them in future.
I've tried this for a test
I've tried this for a test but not working :
PHP
JS :
i m getting this :
Drupal.ajax.prototype.commands.myjscallback is undefined
thank you very much for your help
i also try to add this inside
i also try to add this inside my module
describe here http://api.drupal.org/api/drupal/includes!ajax.inc/group/ajax/7#comment-...
but it not working
Whenever I use commands I use
Whenever I use commands I use ajax_render(), which returns everything in the correct JSON format, maybe that's what you are missing.
I'm not really sure what you mean by 'non callback function', it seems that it is a page callback function. I believe you can do what you are trying to do, but I think it would be better to do it through Drupal.ajax. For example, I would create a new instance and bind the event to the table item, something like...
Then I would change your menu item slightly...
Then in your page callback function you could do...
Also, I don't think there is any need putting
drupal_add_library('system', 'drupal.ajax');in the page callback function, as that needs to go into whatever page your table is in instead.