weixin_33725270 2018-03-16 21:58 采纳率: 0%
浏览 28

如何显示数组PHP:AJAX

As you can see, I have a problem with displaying data in PHP/AJAX. This is my probably second/third question on this forum about that problem. Below I will show you my code. How to display an array from json_encode in PHP using JSON? At the moment I have use dataType 'text' in AJAX, and I gets array like this: [{"name":"yy","surname":"yy","title":"test","gender":"woman"}], I want to display each data from this array. After using dataType JSON, it shows my anything ( with no one error in console log). Someone has any suggestion?

My code:

1.

$(document).ready(function(){
    $(".profile").click(function(){

        var id = $(this).data('id');

        $.ajax({
                method: "GET",
                url: "../functions/getDataFromDB.php",
                dataType: "text",
                data: {id:id},
                success: function(data){

                    console.log(data);

                }
        });

    });
});

2.

if(isset($_GET['id'])){
    $id = $_GET['id'];

    $vv = new AddService();

    $vv->GetPlayer($id);

3.

public function GetPlayer($id){

    $query = "SELECT * FROM test WHERE id={$id}";
    $result = $this->db->query($query);
    if ($result->num_rows <= 0) {
        return false;   
    }

    $this->PlayerInfo[] = $result->fetch_assoc();


    echo json_encode ($this->PlayerInfo);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记