我試圖在單擊父節點(類別)時獲取子節點(在我的情況下是子類別)。但我可以看到沒有Ajax請求發生在我的情況。我使用了本網站的解決方案 - (http://www.miketyka.com/2012/10/lazy-loading-with-jstree-and-ajax/)。這裏是我下面的代碼jstree -jstree中沒有ajax請求
/**
* menu tree generation
*/
$("#menu_tree")
.bind("open_node.jstree", function (e, data) { // this binding will collapse all nodes whenever user expands any 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": { // this will let user to expand or collapse node by clicking on the 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
}
});
HTML部分低於 -
<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 as $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>
我想獲得的數據如下 - (我用笨)
$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);
我只是第一次加載父節點,所有的子節點都應該通過用戶單擊父節點加載。
如果我使用「html_data」而不是「json_data」然後發生的請求,我可以看到加載GIF,但後來我得到這個錯誤「未捕獲錯誤:NotFoundError:DOM異常8」,但如果我使用「json_data」那麼什麼都不會發生,在螢火蟲中沒有ajax請求。
我不明白我在做什麼錯...任何解決方案,請嗎?
你能看到int螢火蟲嗎?是否發送了AJAX請求? Web服務器是否收到它?簡化您的代碼。首先使用ajax中的url。不確定「load_open」是做什麼的。以前從未使用過。 – Radek 2013-04-09 23:23:14
@Radek ---沒有發送ajax請求,這是問題,因爲我甚至不明白在哪裏可以找到錯誤... – rafi 2013-04-10 04:34:00
@Radek ---我試圖通過單擊加載子節點父節點名稱動態與ajax。 – rafi 2013-04-10 04:40:51