国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Ajax請(qǐng)求json數(shù)據(jù)

2019-11-15 02:06:06
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
Ajax請(qǐng)求json數(shù)據(jù)同域請(qǐng)求json數(shù)據(jù)

客戶端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

服務(wù)端端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跨域請(qǐng)求json數(shù)據(jù)

客戶端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

服務(wù)端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


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 张家口市| 轮台县| 兴文县| 宜黄县| 西畴县| 唐山市| 莱州市| 泗水县| 迁安市| 万山特区| 通山县| 菏泽市| 宜城市| 崇礼县| 宜城市| 祁阳县| 洪江市| 汨罗市| 邳州市| 镇康县| 广灵县| 蓬莱市| 九江市| 二连浩特市| 繁昌县| 南京市| 河津市| 同德县| 全州县| 龙口市| 江达县| 增城市| 苗栗县| 广汉市| 泰来县| 尼木县| 察雅县| 呼伦贝尔市| 余江县| 永年县| 罗甸县|