title: Ajax no data return
body: <p>I have a jstree to display in one of my pages. </p>
  
  <p>In this page I make an http request in ajax to get some modified data from the server and print it to my page.</p>
  
  <p>After I do all the things in the server I want to send the edited data back to my page, but when I do that there is nothing displayed.</p>
  
  <p>But on the server page the data is displayed correctly!</p>
  
  <p>I tried to find something like callback functions but I didn't understand much of it.</p>
  
  <p>This is the function that I send to the server page.</p>
  
  <pre><code>function DisegnaAlbero1(){
      var mese    = document.getElementById('mesericerca').value;
      var anno    = document.getElementById('annoricerca').value;
      var strURL2  = "./disegnaalbero.php?mesericerca="+ mese +"&amp;annoricerca=" + anno;
      //alert(strURL); 
      var req = getXMLHTTP();
  
  
      if (req)
      {
          req.onreadystatechange = function()
          {
              if (req.readyState == 4)
              {
                  // only if "OK"
                  if (req.status == 200)
                  {
                      document.getElementById('albero').innerHTML=req.responseText;
  
                  } 
                  else 
                  {
                      alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                  }
              }
          }
      }
      req.open("GET", strURL2, true);
      req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
      req.send(null);
  }
  </code></pre>
  
  <p>I edit it like this:</p>
  
  <pre><code>&lt;link rel="stylesheet" href="dist/themes/default/style.min.css" /&gt;
      &lt;script src="./js/libs/jquery-2.1.0.min.js"&gt;&lt;/script&gt;
      &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="dist/jstree.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      var elementi = [];
  
  
  
          function disegnaAlbero(){
          $('#albero').jstree({
              'core' : {
                  "animation": 0,
                  'data' : 
                      [&lt;?php
                      if (session_id() == "")
                      {
                          session_start();
                      }
  
                      if (isset($_SESSION['id']))
                      {
                          $idutente = $_SESSION['id'];
                          $nomeutente = $_SESSION['fullname'];
                          $email = $_SESSION['email'];
                      }
  
  
  
                      function get_number_of_days_in_month($month, $year) {
                       $date = $year."-".$month."-1";
                      return date("t", strtotime($date));
                      }
  
                      include('./includedb.php');
  
                      $data = array();
                      $index = array();
                      $albero = array();
                      $m = $_GET["mesericerca"];
                      $y = $_GET["annoricerca"];
  
                      if($m &lt; 10) {
                          //$mesesel = "0".$mesesel;
                          $m = "0" . $m;
                          //$giorni  = get_number_of_days_in_month($mesesel, $annosel);
                          $giorni  = get_number_of_days_in_month($m, $y);
                          } else {
                          $giorni  = get_number_of_days_in_month($m, $y);
                          }
  
                      $last_day_this_month = $y . "-" . $m . "-" . $giorni;
                      //echo $last_day_this_month;
  
                      $query = $conn-&gt;query("SELECT id, email, tipoutente, fullname, datainserimento, utentepadre FROM utenti WHERE utentepadre is not null AND datainserimento &lt; '$last_day_this_month'");
  
  
                      $query-&gt;data_seek(0);
                      while ($row = $query-&gt;fetch_assoc()) {
                          $id        = $row["id"];
                          $parent_id = $row["utentepadre"] === NULL ? "NULL" : $row["utentepadre"];
                          $data[$id] = $row;
                          $index[$parent_id][] = $id;
  
                      }
  
                      function trovaCoupon($id)
                      {
                          include('./includedb.php');
                          $mese = $_GET['meseselezionato'];
                          $anno = $_GET['annoselezionato'];
  
                          if ($mese == "") $mese = date('m');
                          if ($anno == "") $anno = date('Y');
  
                          $coupon = 'SI';
                          $result = $conn-&gt;query("SELECT kriga FROM couponregistrati where codcliente = '$id' and meseregistrazione = '$mese' and annoregistrazione = '$anno'");
                          $row = $result-&gt;num_rows;
                          if ($row == 0)
                          {
                              $coupon = 'NO';
                          }
                          return $coupon;
                      }
  
                      /*
                       * Recursive top-down tree traversal example:
                       * Indent and print child nodes
                       */
                      function display_child_nodes($parent_id, $level, $strpadre)
                      {
                          global $data, $index, $albero;
                          $parent_id = $parent_id === NULL ? "NULL" : $parent_id;
                          $numfigli = 0;
  
                          if (isset($index[$parent_id])) {
                              foreach ($index[$parent_id] as $id) {
                                  $numfigli++;
                                  $padre      = $data[$id]["utentepadre"];
                                  $tipo       = $data[$id]["tipoutente"];
                                  $inseritoda = $data[$id]["inseritoda"];
                                  $coupon     = trovaCoupon($data[$id]["id"]);
                                  $icona      = './img/user_'.$coupon.'.png';
                                  if ($tipo == 'FORNITORE')
                                  {
                                      $icona = './img/fornitore.png';
                                  }
                                  if ($tipo == 'GRUPPO PRIVATO')
                                  {
                                      $icona = './img/group_'.$coupon.'.png';
                                  }
                                  if ($tipo == 'GRUPPO ASSOCIAZIONI')
                                  {
                                      $icona = './img/group_'.$coupon.'.png';
                                  }
                                  if ($tipo == 'GRUPPO NEGOZI')
                                  {
                                      $icona = './img/group_'.$coupon.'.png';
                                  }
                                  if (($padre == $inseritoda) &amp;&amp; ($tipo == 'CLIENTE'))
                                  {
                                      $icona = './img/diretto_'.$coupon.'.png';   
                                  }
  
                                  $livello = $level + 1;
                                  $str = '{"icon" : "'.$icona.'", "id" : "'.$data[$id]["id"].'", "parent" : "'.$padre.'", "text" : "'.$data[$id]["fullname"].' ('.$livello.') ['.$data[$id]["email"].']", "state" : { "selected" : false}},'; 
  
                                  echo $strpadre.$str;
                                  $strpadre = "";
                                  display_child_nodes($id, $level + 1, $strpadre);
                              }
                          }
                          if ($numfigli == 0) {
                              echo $strpadre;
                          }
                      }
                      $coupon   = trovaCoupon($idutente);
                      //$strpadre = '{"icon" : "./img/user_'.$coupon.'.png", "id" : "'.$idutente.'", "parent" : "#", "text" : "'.$nomeutente.' ['.$email.']","state" : { "opened" : true, "selected" : true}},';
                      $strpadre = '{"icon" : "./img/user_'.$coupon.'.png", "id" : "'.$idutente.'", "parent" : "#", "text" : "'.$nomeutente.' ['.$email.']","state" : { "opened" : true, "selected": true}},';
                      display_child_nodes($idutente, 0,$strpadre);
                      ?&gt;
                  ],                      
                  'check_callback' : function(o, n, p, i, m) {
                      if(m &amp;&amp; m.dnd &amp;&amp; m.pos !== 'i') { return false; }
                      if(o === "move_node" || o === "copy_node") {
                          if(this.get_node(n).parent === this.get_node(p).id) { return false; }
                      }
                      return true;
                  },
                  'force_text' : true,
                  'themes' : {
                      'responsive' : false,
                      'variant' : 'small',
                      'stripes' : true
                  }
              },
              'sort' : function(a, b) {
                  return this.get_type(a) === this.get_type(b) ? (this.get_text(a) &gt; this.get_text(b) ? 1 : -1) : (this.get_type(a) &gt;= this.get_type(b) ? 1 : -1);
              },
                  'types' : {
                      'default' : { 'icon' : 'folder' },
                      'file' : { 'valid_children' : [], 'icon' : 'folder' }
                  },
                  'unique' : {
                      'duplicate' : function (name, counter) {
                          return name + ' ' + counter;
                      }
                  },
                  'plugins' : ['state','dnd','sort','types','unique', 'search']
          });
  }
  
  $("#s").submit(function(e) {
          e.preventDefault();
          $("#albero").jstree(true).search($("#q").val());
      });
  
  
  
  setTimeout(function() {
          $('#invia').trigger('click');
      }, 1e3);
  
  
  setTimeout(function () {
      $("#albero").jstree("deselect_all");
  }, 2e3);
      refresh = true;
      $("#albero").jstree("deselect_all");
      $("#albero").jstree("refresh"); 
      &lt;/script&gt;
      &lt;div id="albero" class="tree"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>And it displays all the data but in the page that I want it displayed it does not.</p>