Ajax Request JSON data

Source: Internet
Author: User

Request JSON data in the same domain

Client JS Code:

<script>    $.ajax ({        ' http://127.0.0.2/index.php ',        ' GET ',        ' json ' ,        ' Xcajax ', at: ' Goodslist '},        function(JSON) {            $.each (JSON,function  (i) {                   console.log (json[i].title);            })        }    );         </script>
View Code

Service End PHP Code:

functionin_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 _whereORDER by Pid,adid DESC LIMIT 0,10 "; $rs=$this->db->query ($sql);  while($rsList=$this-&GT;DB-&GT;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 CodeRequest JSON data across domains

Client JS Code:

<script>    $.ajax ({        ' GET ',        false,        ' http://zbcn.cn/ index.php ',        ' Jsonp ',        ' Xcajax ', at: ' Goodslist '},        ' callback ',         function (JSON) {            $.each (JSON,function(i) {                   console.log (json[i].title);            })        }    );         </script>
View Code

Service-Side PHP code:

functionin_goodslist () {$callback=$this->fun->accept (' callback ', ' G ');//GET Package        $db _table= Db_prefix. ' Advert '; $db _where= ' WHERE Isclass=1 and Atid=6 '; $bann _array=Array(); $sql= "SELECT * from"$db _table $db _whereORDER by Pid,adid DESC LIMIT 0,10 "; $rs=$this->db->query ($sql);  while($rsList=$this-&GT;DB-&GT;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

Ajax Request JSON data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.