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);
}