Hi guys,
I just can't get this to work I am not sure if my Ajax is returning anything at all but here is the response from my php file:
http://www.designjazz.com/clients/ajax/get_page_data.php?d_id=12[{"id":"ajson12","parent":"#","text":"Welcome"},{"id":"ajson13","parent":"#","text":"Getting to Us"},{"id":"ajson14","parent":"13","text":"About Us"},{"id":"ajson15","parent":"13","text":"Visit Us"},{"id":"ajson16","parent":"13","text":"Bus Routes"},{"id":"ajson17","parent":"#","text":"Choices"},{"id":"ajson18","parent":"#","text":"Guidance"},{"id":"ajson19","parent":"#","text":"Facilities"}]get_page.data.php code:
Start:header('Content-Type: application/json');
Middle:Censored for security but you can see the output above.
End:echo json_encode($page_data);
Javascript on my page where the jsTree is $DOC['d_id']=12:<script src="../js/jquery-1.11.0.min.js"></script>
<script src="../js/jstree.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$('#jstree1').jstree({ 'core' : {
// I usually configure the plugin that handles the data first
// This example uses JSON as it is most common
"json_data" : {
// This tree is ajax enabled - as this is most common, and maybe a bit more complex
// All the options are almost the same as jQuery's AJAX (read the docs)
"ajax" : {
// the URL to fetch the data
"type" : "POST",
"url" : "./ajax/get_page_data.php",
"dataType": "JSON",
"contentType": "application/json;",
"data":
"d_id="+<?=$DOC['d_id']?>,
"success" : function (data) {
// 'data' is a JSON object which we can access directly.
// Evaluate the data.success member and do something appropriate...
console.log(data);
alert(data);
if (data.success == true){
$('#section1').html(data);
} else {
$('#section2').html(data);
}
},
"error": function (error) {
alert('error; ' + eval(error));
}
}
}
} });
});
</script>