之前的博客里记录了php解决跨域的方案:jsonp;

除了jsonp之后,还是通过header函数设置响应头解决跨域问题:

设置允许访问的域名:

  1. 允许全部的域名访问
    header("access-control-allow-origin:*");
  2. 允许指定域名访问
    header( 'access-control-allow-origin:http://a.test.com' );  

设置允许访问的请求方式:

  1.  一种或者多种
    header('access-control-allow-methods:post,get,options,delete'); 
  2. 全部
    header('access-control-allow-methods:*');  

然后根据需要再设置其他的参数……