The screen cast from Sean Buscay : How to use Drupal 7's built-in Ajax framework almost do that. The only difference is that the loaded nobe is always display on the same div base is id.
<?php
function ajax_reader_init() {
drupal_add_js('misc/jquery.form.js');
drupal_add_library('system', 'drupal.ajax');
}
/**
* Implements hook_menu().
*/
function ajax_reader_menu() {
// A menu callback is required when using ajax outside of the Form API.
$items['ajax-reader'] = array(
'page callback' => 'ajax_link_response',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function ajax_link_response($type = 'ajax', $nid = 0) {
$output = _ajax_reader_load_noder($nid);
if ($type == 'ajax') {
$commands = array();
$commands[] = ajax_command_replace('#block-block-6', '<div id="block-block-6">' . $output . '</div>');
$page = array(
'#type' => 'ajax',
'#commands' => $commands
);
ajax_deliver($page);
}
else {
$output = '<div id="content">' . $output . '</div>';
return $output;
}
}
function _ajax_reader_load_noder($nid = 0) {
return views_embed_view ('front','block', $nid);
}
Now the problem is I don't wan to send the result always to the same div. I wan to replace the view row by the new ajax loaded view. But I don't know how to pass the result to the good div.
$commands[] = ajax_command_replace('#block-block-6', '<div id="block-block-6">'
Lets say I click the title of the third view row the nid of this third element is process in the module but I nead a way to pass the parent div class (view-row-3) to the function ajax_reader_menu()
Did anybody can guide me on that, thanks
I know that I'm not super clear, but all this still vary obscure for the moment, sorry.