1. 程式人生 > >Jquery 實現跨域處理

Jquery 實現跨域處理

cati ech data join result rom exit lis 代碼

JS部分代碼:

$.ajax({  
    url:url,  
    dataType:‘jsonp‘,  
    data:{title:title},  
    jsonp:‘callback‘,  
    success:function(lis) {
        $(‘.mylist‘).html(‘‘);
        var txt=‘‘;
       for (x in lis) {
          txt=txt+‘<li>‘+lis[x].title+‘</li>‘;
    }
    $(‘.mylist‘).html(txt);
  }
});

  

後臺部分代碼:

     $title=‘‘;
    	if (isset($_REQUEST[‘title‘])) {
    		$title=trim($_REQUEST[‘title‘]);
    	}
    	$sql="SELECT * FROM `v9_news` as a INNER JOIN `v9_news_data` AS b ON a.id=b.id WHERE a.catid IN(2349,2372,3614,2343,2344,2345,2346) AND subtitle LIKE ‘%$title%‘";
        $result = $this->db->query($sql);
        $info = $this->db->fetch_array($result);
        $callback = $_REQUEST[‘callback‘];
        echo $callback.‘(‘.json_encode($info).‘)‘;exit;

  

Jquery 實現跨域處理