PHP + js 网站跨域处理
									
				
			解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
js采取jquery的ajax请求:
$.ajax({
	url: 'http://poem.com/hzdjapi.php',
	type: 'GET',
	data: {i:tar},
	async: false,
	cache: false,
	dataType: 'JSON',
	success: function(data){
		console.log(data);
	}
});
服务器端PHP,使用:
header('Access-Control-Allow-Origin: *');
那么Server端更多的处理方法如下:
header('Access-Control-Allow-Origin: *'); // 所有域名可以访问
header('Access-Control-Allow-Origin: http://h5.cleey.com'); // 特定域名可以来访问
// 指定顶级域名;多个域名动态设置
if( preg_match('/.*cleey.com$/',$_SERVER['HTTP_ORIGIN']) ){
    header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
}
还有一个解决方法是采用callback回调的方式,具体见:/blog/single/id/68.html