I am using PHP with RESTful API, I have a problem with GET request. My function returns an array of objects, which i can see in my browser if I press F12->Network->function.php->Response
This is what is in response:
{"data":[{"content":"test123","user_id":"2","user_email":"0","username":"admin","ad_id":"1","date":"2020-03-28"}]}
Now going back to $.ajax method,if i try to parse this JSON data, it parses to "1" instead to the array of objects. Below is my $.ajax method and function that loads these objects
$.ajax({method:"GET", url:"api.php/loadComment/"+$('#ad_id').val(),done:function(data){
$comments = JSON.parse(data);
console.log($comments);
}});
switch method in my api.php file, this succesfully loads objects into $comments:
switch($method){
case 'GET':
$comments["data"] = Comment::returnAll($db,$request[1]);
echo json_encode($comments);
break;
}