jquery - NO ajax request is happening in jstree -
i trying sub nodes (in case sub categories) on clicking in parent nodes (categories). can see no ajax request happening in case. have used solution website - (http://www.miketyka.com/2012/10/lazy-loading-with-jstree-and-ajax/). here jstree code below -
/** * menu tree generation */ $("#menu_tree") .bind("open_node.jstree", function (e, data) { // binding collapse nodes whenever user expands single node data.rslt.obj.siblings().filter(".jstree-open").each(function () { data.inst.close_node(this); }); }) .jstree({ "json_data": { "ajax": { "url": base_url + "draw/get_child" } }, "types": { // let user expand or collapse node clicking on node title "types": { "default": { "select_node": function (e) { this.toggle_node(e); return false; } } } }, "core": { "html_titles": true, "load_open": true }, "plugins": ["themes", "json_data", "html_data", "types", "ui"], "themes": { "theme": "apple", "dots": true, "icons": true } });
the html part below -
<div class="" id="menu_tree" style="width: 500px;z-index: 1; float: right;position: relative;"> <ul class="" style="position: absolute;top: 0px;left: 0px;"> <?php if (!empty($parent_categories)) { foreach ($parent_categories $parent_categories) { ?> <li id="cat<?php echo $parent_categories->objcat_id; ?>"> <a href="#" class=""><?php echo $parent_categories->category_name; ?></a> </li> <?php } } ?> </ul> </div>
the data trying below - (i'm using codeigniter)
$this->load->model('object_category_model'); $result = array(); $sub_category = $this->object_category_model->get_subcategories_by_category_id($this->input->post('parent_id')); echo json_encode($sub_category);
i loading parent nodes first time, child nodes should load user click on parent nodes.
if use "html_data" rather "json_data" request occurs , can see loading gif error "uncaught error: notfounderror: dom exception 8", if use "json_data" nothing happens, no ajax request in firebug.
i can't understand what's wrong doing... solution please?
after 4 days of trying, have found problem, wrong doing. returning data php part wrong format. have fixed format , running well, forgot use "jstree-closed" class. correct format (format using) given below-
$sub_category = $this->object_category_model->get_subcategories_by_category_id($_get['id']); if ($sub_category != false) { foreach ($sub_category $sub_category) { $result = '<li class="jstree-closed cat" id="' . $sub_category->objcat_id . '"><a href="#">' . $sub_category->category_name . '</a></li>'; echo $result; } }
and have used html_data rather json_data.
"html_data" : { //generating child nodes of selected parent node dynamically using ajax "ajax" : { "url" : base_url + "draw/get_child", "data" : function (n) { return { id : n.attr ? n.attr("id") : 0 }; } } }
thanks trying me. :-)
Comments
Post a Comment