douhuo1738 2013-07-14 15:15
浏览 41
已采纳

JSON查询问题

I Use a json onclick script for triggering a php function. I call the php function with:

$('#dtable').on('click', '[name=option3]', function () {
    var select = $(this);
    var id = select.attr('id');
    $.post('index.php/stop/'+id+'', function(json) {
            if (json && json.status) {
                $("#failure").show().delay(2500).fadeOut(1500);
            } else {
                $("#success").show().delay(2500).fadeOut(1500);
            }
        }
    );
} );

If the item is trigger he calls a slim property in my index.php

$admin->slim->post('/stop/:action', function($action) use ($admin) {
    $admin->slim->contentType('application/json');
    echo json_encode($admin->cont->Stop($action));

After this he triggert the function

function Stop($action) {
    $port = $action;
    $connection = @fsockopen($this->cfg->base_host, $port, $errno, $errstr, 1);
    if (!$connection) {
        return false;
    } else {
        $pid = $this->db->query("SELECT pid FROM testdb WHERE port='" . $port . "'", SQL_ALL, SQL_ASSOC);
        if ($pid == "") {
            return false;
        } else {
                  ......
                }
            }
        }
    }
}

the only thing is that the answer from json is always success but there is no return from true or false from the function

Does someone knows what i doing wrong or can someone give me some advice.

  • Added more information about the function
  • 写回答

1条回答 默认 最新

  • dongxie3963 2013-07-14 15:50
    关注

    Use alert(json); before if (json && json.status) to see what you get. I'm sure json is not what you expect. It seems json == false (because function Stop() return false) and there is no json.status - or maybe rest of your Stop function return something more.

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分