【问题标题】:Get php fetch array values from json encode jquery从json编码jquery获取php获取数组值
【发布时间】:2015-12-23 10:05:19
【问题描述】:

这是我的代码,实际上我是在 json 编码数据中插入一个数组并通过 jquery 返回。

        $list_type_query = "select * from assettype";
        //the asset type table contains (id & type) column 
        $query = mysqli_query($conn, $list_type_query);
        while($r = mysqli_fetch_array($query)){
            $result_value = array("Status" => "haslist", "list" => $r);
        }

这是 jquery 方面。

        case "loaddefaultmodel":                       
        var showtype = $('#sh');                       
        var showvalue = '<span>'+data['list']+'</span>';
        showtype.html(showvalue);
        break;

$('#sh') 是一个 div,我需要在 div 内的 span 中显示所有类型的内容。

如果我使用 data['list'][0]['type'] 我得到一个对象 0 值。

如何在 div 中动态地一一显示所有值。

【问题讨论】:

    标签: javascript jquery json


    【解决方案1】:

    我认为您的 php 代码中存在问题。 因为在每个循环中,$r 只是获取当前的每一个索引数据,而 $result_value 只是获取当前的索引数据。

    你可以试试这个……

        $list_type_query = "select * from assettype";
        //the asset type table contains (id & type) column 
        $query = mysqli_query($conn, $list_type_query);
        $all_data = array();
        while($r = mysqli_fetch_array($query)){
            $all_data[] = $r;
        }
        $result_value = array("Status" => "haslist", "list" => $all_data);
    

    【讨论】:

    • 我在像 Object {Status: "haslist", list: Array[6]}这样的数组中得到结果
    • and in list array list: Array[6] 0: Object 1: Object 2: Object 3: Object 4: Object 5: Object
    • 我需要如何在不手动提供任何对象的情况下自动显示 div 中的所有对象数据。
    猜你喜欢
    • 2012-09-07
    • 1970-01-01
    • 2015-03-15
    • 2013-07-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多