简体   繁体   English

附加元素未显示CSS ISSUE JAVASCRIPT PHP

[英]Appended elements are not showing CSS ISSUE JAVASCRIPT PHP

I have experiencing some problems with fetching the grandchilds from my db table: referrals . 我从数据库表中获取孙子孙时遇到了一些问题: Referrals However, it seems that my code can actually fetch the usernamee of my grandchilds . 但是,看来我的代码实际上可以获取孙子用户名 But it is not appearing below my child's line and there is no error in INSPECT . 但是它没有出现在我孩子的线下,并且INSPECT中没有错误

Please see the OUTPUT image I attached here: Attached here are the images of the output of my code: 请查看我在此处附加的输出图像:以下是我的代码输出的图像:

OUTPUT

This is the UPDATED database table name referrals: 这是UPDATED数据库表名称的引用: 在此处输入图片说明

I used Javascript to fetch the data's inside "referrals" table 我使用Javascript来获取数据的“引荐”表中的内容

<!-- GENEOLOGY TREE -->
    <div class="tree">
       <?php $id = 1; ?>
          <ul>
             <li>
               <div id="parent_account"><a href="#"><img src="user.png" alt="Avatar" style="width:50px"/></br>Parent<?php echo $id; ?></a></div>
             </li>
        </ul>
      </div>
<!-- END OF GENOLOFY TREE -->


  <script>
$(document).ready(function(){
    // start get children
    var _id = "<?php echo $id ?>";
    var child = "";
    var child_id = [];
    var gchild_id = [];
    var count = 0;

    $.post('get_child_referrals.php', { id:_id }).done(function(response){
        var response = jQuery.parseJSON(response);
        var referred = response["referred"];
        var referred_len = response["referred"].length;
        if(referred_len > 0){
            child += "<ul>";
            for(var x = 0; x < referred_len; x++) {
                console.log(referred[x]["usernamee"]);
                count += 1;
                child_id[x] = referred[x]["id"];
                child += "<li id='child"+x+"'><a href="+x+"><img src='user.png' alt='Avatar' style='width:50px'/><br>Child "+referred[x]["usernamee"]+"</a></li>";
            }
            child += "</ul>";
            console.log(child);
            $("#parent_account").append(child);
            // start get grandchildren
        // console.log(child_id);
        var gchild_len = child_id.length;
        // console.log(gchild_len);
        for(i = 0; i < gchild_len; i++){
            gchild = "";
            _id = child_id[i];
            // console.log(_id);
            $.post('get_child_referrals.php', { id:_id }).done(function(response){
                gresponse = jQuery.parseJSON(response);
                greferred = gresponse["referred"];
                greferred_len = gresponse["referred"].length;
                if(greferred_len > 0){
                    gchild += "<ul>";
                    for(y = 0; y < greferred_len; y++) {
                        gchild_id[y] = greferred[y]["id"];
                        console.log(greferred[y]["usernamee"]);
                        gchild += "<li id='gchild"+y+"'><a href="+y+"><img src='user.png' alt='Avatar' style='width:50px'/><br>Child "+greferred[y]["usernamee"]+"</a></li>";
                    }
                    gchild += "</ul>";
                    console.log($("#child"+i).length);
                    console.log(gchild);
                    $("#child"+i).append(gchild);
                }
            });
        }
        // end get grandchildren
        }
    });
    // end get children
});
</script>​

get_child_referrals.php get_child_referrals.php

include('connectdb.php');
$response = array();
$response["referred"] = array();
$id = $_POST['id'];
$sql = "SELECT * FROM referrals WHERE referral_id='$id'"; // MY RECRUITERS
$result = $conn->query($sql);
while($data = $result->fetch_assoc()) {
                array_push($response["referred"], $data);
}
echo json_encode($response);

For more info, this is my logs on my inspect console: 有关更多信息,这是我在检查控制台上的日志: 在此处输入图片说明

First,Inspect for the username.Check if its coming in HTML.Sometimes, it is rendered but hidden.Secondly, just just console the child element,to confirm you are appending it to the right one. 首先,检查用户名。检查用户名是否包含在HTML中。有时,它已呈现但隐藏了。其次,只需控制台子元素,以确认您将其追加到正确的子元素上。

console.log($(child)); 的console.log($(子));

I tried your code in my local, and got an output as in the pic.Check if its something that you want to get. 我在本地尝试了您的代码,并得到了如图所示的输出。检查是否想要获得它。

在此处输入图片说明

So looking at your console, this line console.log($("#child"+i).length); 因此, console.log($("#child"+i).length);您的控制台,该行console.log($("#child"+i).length); appears to be returning 0 which would mean that the element in question doesn't seem to exist. 似乎正在返回0 ,这意味着所讨论的元素似乎不存在。

Can you log this without the .length and make sure that it is still getting the right element. 您是否可以在没有.length情况下登录并确保它仍然获取正确的元素?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM