我有一个jstree可以显示在我的一个页面中。
在这个页面中,我在ajax中发出一个http请求,从服务器获取一些修改后的数据并将其打印到我的页面。
在我完成服务器中的所有操作后,我想将编辑后的数据发送回我的页面,但是当我这样做时,没有显示任何内容。
但是在服务器页面上数据显示正确!
我试图找回类似回调函数的东西,但我对它的了解并不多。
这是我发送到服务器页面的功能。
function DisegnaAlbero1(){
var mese = document.getElementById('mesericerca').value;
var anno = document.getElementById('annoricerca').value;
var strURL2 = "./disegnaalbero.php?mesericerca="+ mese +"&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);
}
我这样编辑:
<link rel="stylesheet" href="dist/themes/default/style.min.css" />
<script src="./js/libs/jquery-2.1.0.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="dist/jstree.min.js"></script>
<script>
var elementi = [];
function disegnaAlbero(){
$('#albero').jstree({
'core' : {
"animation": 0,
'data' :
[<?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 < 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->query("SELECT id, email, tipoutente, fullname, datainserimento, utentepadre FROM utenti WHERE utentepadre is not null AND datainserimento < '$last_day_this_month'");
$query->data_seek(0);
while ($row = $query->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->query("SELECT kriga FROM couponregistrati where codcliente = '$id' and meseregistrazione = '$mese' and annoregistrazione = '$anno'");
$row = $result->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) && ($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);
?>
],
'check_callback' : function(o, n, p, i, m) {
if(m && m.dnd && 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) > this.get_text(b) ? 1 : -1) : (this.get_type(a) >= 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");
</script>
<div id="albero" class="tree"></div>
它显示所有数据,但在我想要显示的页面中却没有显示。