Currently, I made script, which after onclick event,sending question to the database and showing data in console.log( from array ). This all works correctly, but.. I want to show data from array in the different position in my code. When I try to use DataType 'json' and then show some data, then it display in my console.log nothing. So, my question is: How to fix problem with displaying data? Is it a good idea as you see?
Below you see my current code:
    $(document).ready(function(){
    $(".profile").click(function(){
        var id = $(this).data('id');
        //console.log(id);
        $.ajax({
            method: "GET",
            url: "../functions/getDataFromDB.php",
            dataType: "text",
            data: {id:id},
            success: function(data){
                    console.log(data);
            }
        });
    });
});
:
    public function GetPlayer($id){
    $id = $_GET['id'];
    $query = "SELECT name,surname FROM zawodnik WHERE id='".$id."'";
    $result = $this->db->query($query);
    if ($result->num_rows>0) {
        while($row = $result->fetch_assoc()){
            $this->PlayerInfo[] = $row;
        }
        return $this->PlayerInfo;
    }else {
        return false;
    }
}
:
    $info = array();
    $id = $_GET['id'];
    $vv = new AddService();
    foreach($vv->GetPlayer($id) as $data){
        $info[0] = $data['name'];
        $info[1] = $data['surname'];
    }
    echo json_encode($info);
 
    