Jquery 实现跨域处理

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;

  

posted @ 2017-09-20 09:03  zhuzhipeng  阅读(313)  评论(0编辑  收藏  举报