I am currently loading my view through an ajax request in my custom module:
$.getJSON('/reports/summarized-progress/get_output_activities/'+nid, null,activities);
The drupal page for the above request returns the following:
$output_arg=arg(3);
$html="";
$activities=views_embed_view('activities','block_activities',$output_arg); //this returns a view accordion view
if(!empty($activities)) {
$html.='';
$html.=$activities;
$html.='';
}
drupal_json_output(array('data'=>$html));
The accordion/collapsible functionality is not working on the loaded content. Any ideas whether I need to include through module_load_include any files in my custom module? What needs to be done for this to work?
Whenever you load content through ajax request, you have to ensure that the needed js settings/files are loaded along with your content.
In most cases, the $javascript static variable that is filled during a content load through drupal_add_js() is not sent to the browser, but you can do this manually :
Note : If your accordion view rely on a specific .js file, ensure this file is sourced inside every page where ajax requests take place. Usually, you'll have to explicitly source this file if such a page is loaded (full page load) without the view.
You can achieve this in a hook_page_preprocess() implementation :
... or by including the file when the content is requested (as we do for Drupal.settings), just add a script tag in the $script variable in the ajax callback :
Hope this helps!