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 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题