dongzichan2886 2018-06-01 11:48
浏览 66
已采纳

GET http:// localhost / v5 / api / checker 404(Not Found)Slim

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)
        }
    });
}
  • 写回答

1条回答 默认 最新

  • dongli1920 2018-06-01 15:38
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么