header("Access-Control-Allow-Origin: http://a.com"); // 允许a.com发起的跨域请求
//如果需要设置允许所有域名发起的跨域请求,可以使用通配符 *
header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
后端设置跨域header
该博客介绍了如何在后端通过设置HTTP响应头`Access-Control-Allow-Origin`来允许特定或任何域名发起的跨域请求,确保前端与后端API交互的顺利进行。同时提到了`Access-Control-Allow-Headers`用于指定允许的自定义请求头。
1986

被折叠的 条评论
为什么被折叠?



