I'm trying to do a function with call AJAX to php but when I click the button it shows this error, some one knows how can I solve it? My code below.
PHP:
$app->get('/checker', function () {
$jsonContents = file_get_contents('data/data.json');
$data= json_decode($jsonContents, true);
foreach ($data as $key =>[$value]) {
$host = $value['domain'];
exec('ping -c 2' . $host,$output,$result);
ECHO $result;
}
});
JS AJAX:
function CallChecker() {
$.ajax({
type: 'GET',
url: 'api/checker',
dataType: 'json',
success: function(data) {
alert(data)
}
});
}
I have strong doubts that Slim router follows your directories path. I don't know your complete configuration, so I may be mistaken, but try to access http://localhost/checker or http://localhost/v5/checker and see if it shows you something.
Also in javascript you set URL as relative, which may work only if you call it from the home page. Instead you should add slash like this:
url: '/api/checker',
But again - try '/checker' or '/v5/checker', I believe it's the way how most routers should work.