php - How to save changes back to databse from jsTree? -


i want save changes make on jstree database. tried different methods cant work. working in codeigniter. please me if can. thank you. here code, view.php:

 <button id="target" type="submit">click here</button>  <script type="text/javascript">     $(document).ready(function () {         $('#tree-container').on('changed.jstree', function (e, data) {             var i, j, r = [];             // var state = false;              (i = 0, j = data.selected.length; < j; i++) {                 r.push(data.instance.get_node(data.selected[i]).id);             }             $('#txttuser').val(r.join(','));         }).jstree({             'plugins': ["checkbox", "dnd", "search", "contextmenu"],             'core': {                 "check_callback" : true,                 "multiple": true,                 'data': {                     "url": "getchildren",                     "datatype": "json"                 }             },             'checkbox': {                 three_state: false,                 cascade: 'up'             },             'plugins': ["dnd","contextmenu","search","wholerow"],         }         );     });     $( "#target" ).click(function() {         var v =$('#tree-container').jstree(true).get_json();              var mytext = json.stringify(v);              alert(mytext); }); </script>  <div class="row">      <div class="container">          <input type="hidden" name="node" id="node" value="" />          <div class="form-group"> <div id="tree-container"></div>          </div>      </div>  </div> 

controller.php:

 function getchildren() {       $this->load->model('category_model');      $result = $this->category_model->tree_all();       $itemsbyreference = array();   // build array of item references:          foreach($result $key => &$item) {          $itemsbyreference[$item['category_id']] = &$item;   // children array:         $itemsbyreference[$item['category_id']]['children'] = array();   // empty data class (so json_encode adds "data: {}" )          $itemsbyreference[$item['category_id']]['data'] = new stdclass();       }   // set items children of relevant parent item.      foreach($result $key => &$item)          if($item['parent_id'] &&       isset($itemsbyreference[$item['parent_id']]))              $itemsbyreference [$item['parent_id']]['children'][] = &$item;     // remove items added parents elsewhere:      foreach($result $key => &$item) {          if($item['parent_id'] &&    isset($itemsbyreference[$item['parent_id']]))              unset($result[$key]);         }       foreach ($result $row) {          $data[] = $row;       }   // encode:  echo json_encode($data);       } 

model.php:

 function tree_all() {  $result = $this->db->query("select category_id, category,category text,   parent_id category ")->result_array();  foreach ($result $row) {      $data[] = $row;   }      return $data;   } 

pleeaaase heeelp meee!!! trying figure out days.

to manage add, edit, update jstree, first of download jstree.js , check following line:

"create" : { 

this block of code executes when click on create, put create code logic here ajax call add / update database.

in same way can manage edit, delete.

note: edit, delete after create

ajax syntax:

$.ajax({   url : '<?php echo base_url().'/controllerfunction' ?>',   method : 'post',   data: {     key : value   },   success: function(response)  // response controller function   {      // code here   } }); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -