• Ajax请求json数据


    同域请求json数据

    客户端js代码:

    <script>
        $.ajax({
            url: 'http://127.0.0.2/index.php',
            type: 'GET',
            dataType: 'json',
            data: {ac: 'xcajax',at: 'goodslist'},
            success: function(json){
                $.each(json,function(i){
                       console.log(json[i].title);
                })
            }
        });
        
        
    </script>
    View Code

    服务端端PHP代码:

    function in_goodslist() {
            $callback = $this->fun->accept('callback', 'G');
            $db_table = db_prefix . 'advert';
            $db_where = ' WHERE isclass=1 AND atid=6';
            $bann_array = array();
            $sql = "SELECT * FROM $db_table $db_where ORDER BY pid,adid DESC LIMIT 0,10";
            $rs = $this->db->query($sql);
            while ($rsList = $this->db->fetch_assoc($rs)) {
    
                if ($rsList['islink'] == 2 && $rsList['gotoid'] > 0) {
                    $docread = $this->get_documentview($rsList['gotoid']);
                    if ($docread['did'] > 0) $rsList['url'] = $this->get_link('doc', $docread, $lngpack);
                }
    
                if ($rsList['istime'] == 1) {
                    if ($rsList['starttime'] < time() && $rsList['endtime'] > time()) {
                        $bann_array[] = $rsList;
                    }
                } else {
                    $bann_array[] = $rsList;
                }
            }
            $json = json_encode($bann_array);
            //$json = $bann_array;
            echo $callback."($json)";
        }
    View Code

    跨域请求json数据

    客户端js代码:

    <script>
        $.ajax({
            type: 'GET',
            async: false,
            url: 'http://zbcn.cn/index.php',
            dataType: 'jsonp',
            data: {ac: 'xcajax',at: 'goodslist'},
            jsonp: 'callback',
            success: function(json){
                $.each(json,function(i){
                       console.log(json[i].title);
                })
            }
        });
        
        
    </script>
    View Code

    服务端php代码:

    function in_goodslist() {
            $callback = $this->fun->accept('callback', 'G');//GET 封装
            $db_table = db_prefix . 'advert';
            $db_where = ' WHERE isclass=1 AND atid=6';
            $bann_array = array();
            $sql = "SELECT * FROM $db_table $db_where ORDER BY pid,adid DESC LIMIT 0,10";
            $rs = $this->db->query($sql);
            while ($rsList = $this->db->fetch_assoc($rs)) {
    
                if ($rsList['islink'] == 2 && $rsList['gotoid'] > 0) {
                    $docread = $this->get_documentview($rsList['gotoid']);
                    if ($docread['did'] > 0) $rsList['url'] = $this->get_link('doc', $docread, $lngpack);
                }
    
                if ($rsList['istime'] == 1) {
                    if ($rsList['starttime'] < time() && $rsList['endtime'] > time()) {
                        $bann_array[] = $rsList;
                    }
                } else {
                    $bann_array[] = $rsList;
                }
            }
            $json = json_encode($bann_array);
            echo $callback."($json)";
        }
    View Code
  • 相关阅读:
    valgrind内存检测
    uosdeepin商店下载的软件deb包位置
    jmeter中获取到token,又因为现在都是JWT的所以需要添加Bearer 和获取到的token进行拼接
    jmeter json提取器
    jmeter命令行启动
    linux 中把文件内容变成空,不删除文件
    94--分布式事务五-Seata AT模式-Spring Cloud微服务案例(添加AT事务)
    94--Docker(概念/镜像操作/数据管理/网络/互联/构建镜像)
    93--分布式事务四-Seata AT模式-Spring Cloud微服务案例(无事务)
    93--分布式事务二-Seata AT 模式
  • 原文地址:https://www.cnblogs.com/ahhg/p/4272182.html
Copyright © 2020-2023  润新知