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->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 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->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
Ajax Request JSON data