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 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等