首页 > 代码库 > ajax跨域之设置Access-Control-Allow-Origin

ajax跨域之设置Access-Control-Allow-Origin

通过在服务器端设置请求头的源可以实现跨域

 

public function test_ajax()
{
header("Access-Control-Allow-Origin: http://127.0.0.1:63851");
$arr = getallheaders();
foreach($arr as $key=>$val){
$data[$key] = $val;
}
echo json_encode($data);

exit;

}

ajax跨域之设置Access-Control-Allow-Origin