weixin_33690367 2017-11-20 10:08 采纳率: 0%
浏览 20

Ajax没有数据返回

I have a jstree to display in one of my pages.

In this page I make an http request in ajax to get some modified data from the server and print it to my page.

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.

But on the server page the data is displayed correctly!

I tried to find something like callback functions but I didn't understand much of it.

This is the function that I send to the server page.

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:
" + req.statusText);
                }
            }
        }
    }
    req.open("GET", strURL2, true);
    req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    req.send(null);
}

I edit it like this:

<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>

And it displays all the data but in the page that I want it displayed it does not.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
    • ¥15 关于arduino编程toCharArray()函数的使用
    • ¥100 vc++混合CEF采用CLR方式编译报错
    • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
    • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
    • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
    • ¥50 如何openEuler 22.03上安装配置drbd
    • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
    • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
    • ¥15 Windows11, backspace, enter, space键失灵