Php is returning "no data found" on ajax request. Here is my php code and the ajax call. In the network section php is request is not showing up. But in the console a error saying that no data found is appearing. Please help out with this.
<?php
include 'dblinker.php';
function getDetails(){
try {
$link = linkToPoints();
$handle = $link->prepare("SELECT * FROM leafly WHERE id < 11");
$handle->execute();
if(!($handle->rowCount())) {
return "No data exists";
}
$result=$handle->fetchAll(\PDO::FETCH_OBJ);
return json_encode($result);
}
catch(Exception $e){
return "Connection Error";
}
}
echo getDetails();
?>
This is my JS file.
var timer;
$(document).ready(function(){
fetchdata = function(){
$.ajax({
url: 'services/get_data.php',
type: 'GET',
success: function(json) {
console.log(json)
var json1 = jQuery.parseJSON(json);
for(i=0; i < json1.length; i++)
{
tr = $('<tr/>');
tr.append("<td>" + json1[i].id + "</td>");
tr.append("<td>" + json1[i].mod_name + "</td>");
tr.append("<td>" + json1[i].product_type_id + "</td>");
onemore=tr
$('#device_1').append(tr.clone());
$('#device_2').append(onemore.clone());
}
}
});
}
fetchdata();
$("#start").click(function() {
timer = setInterval(function(){
$("#device_1,#device_2").find('tr').remove();
fetchdata();
},1000);
});
$("#stop").click(function() {
clearInterval(timer);
});
});