跨域问题是开发经常遇到的问题,最近整理知识点索性写出来仅供大家参考,封装或者指定方法里写入下边的代码即可!!!
- 指定域名访问
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Origin:https://baidu.com');
header('Access-Control-Allow-Headers:Content-Type');
header('Access-Control-Allow-Methods:POST, GET, PUT');
header('Access-Control-Expose-Headers:Content-Length');
header('Access-Control-Max-Age: 3600');
- 允许所有域名访问
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Headers:Content-Type');
header('Access-Control-Allow-Methods:POST, GET, PUT');
header('Access-Control-Expose-Headers:Content-Length');
header('Access-Control-Max-Age: 3600');