Ajax跨域问题,当我们在一个网站上通过ajax请求另外一个域名的api的时候,这时候就会遇见错误:No ‘AcceControl-Allow-Origin’ headerss- is present on the requested resource.
当我们服务器是nginx的时候,添加以下代码到Nginx配置文件里面:
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
重启nginx生效.
Be the First to comment.