I have an Ajax Request that is getting data from my database, specifically two columns from it, company_id and people_id, I need to test the result that comes from the json result, I need to check if a specific people_id exists in the result,

我有一个从我的数据库获取数据的Ajax请求,特别是它的两列,company_id和people_id,我需要测试来自json结果的结果,我需要检查结果中是否存在特定的people_id,

Here is my Ajax Request

这是我的Ajax请求

Ext.Ajax.request({
    url: 'system/index.php',
    method: 'POST',
    params: {
        class: 'CompanyPeople',
        method: 'secget',
        data: Ext.encode({
            people_id: Ext.getCmp('peopleGrid').selectedRecord.data.people_id
        })
    },
    success: function (response) {

    },
    failure: function () {

    }
});

I thought I could do this following code in the success function but it didnt work

我认为我可以在成功函数中执行以下代码,但它不起作用

if (data == 0) {
    Ext.MessageBox.alert('Status', 'Person is not attached to anything bud!.');
}
else {
    Ext.MessageBox.alert('Status', 'Person already attached to another company.');
}

Also here is my php

这也是我的PHP

class CompanyPeople extends Connect {

    function __construct() {
        parent::__construct();
    }

    public function secget($vars) {
        $sql = "SELECT * FROM CompanyPeople where people_id={$vars->data->people_id}";

        $data = array();

        $total = 0;
        if ($result = $vars->db->query($sql)) {
            while ($row = $result->fetch_assoc()) {
                $data[] = array("people_id" => intval($row["people_id"]));
                $total++;
            }
            $result->free();
        }

        echo json_encode(array("success" => true, "total" => $total, "topics" => $data));
    }
}

1 个解决方案

#1


1

I think something like this should work:

我认为这样的事情应该有效:

success: function( response ){
    if(response.success === true) {
        var personExist = false;

        for(var i = 0; i < response.topics.lenght; ++i) {
            // Your specific people_id in myValue
            if(response.topics[i]['people_id'] === myValue) {
                personExist = true;
                break;
            }
        }
    }
},

更多相关文章

  1. 从函数返回2个值[duplicate]
  2. PHP常量PHP_SAPI与函数php_sapi_name()简介,PHP运行环境检测
  3. PHP递归函数删除所有子节点导致stackoverflow
  4. 使用 PHP usort() 通过用户自定义的比较函数对数组进行排序
  5. [开心学php100天]第五天:string函数(上)
  6. curl获取网页内容出现乱码或为空的解决方案,另附curl_getinfo函数
  7. APMServ 在 Win7 下出现“APMServ-Apache 服务因 函数不正确。
  8. 本机PHP函数将授予我直接访问字符串部分而无需创建临时数组的权
  9. php的冷门函数之——call_user_func_array,func_get_args,func_n

随机推荐

  1. 深入理解跳表在Redis中的应用
  2. Python办公自动化|从Excel到Word
  3. Pyecharts制作地图的几种方法评析
  4. 一道Leetcode数据库题的三种解法|文末送书
  5. 你在的城市撒币了吗?Python爬取全国各城市
  6. LeetCode数据库篇|175组合两个表
  7. 收藏|我的Mysql学习笔记
  8. 51CTO学员:PMP考后感言
  9. 实战|Python数据分析可视化并打包
  10. 深入理解跳跃链表[一]