XMLHttpRequest cannot load http://xxxx. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://yyyy’ is therefore not allowed access.
PHP:
<?php header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept'); ?>
Nginx:
在nginx.conf中配置
nginx.conf位置
$ nginx -t
http { ...... add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; }
这样就可以实现GET,POST,OPTIONS的跨域请求的支持
也可以 add_header Access-Control-Allow-Origin http://huangshiyang.com; –指定允许的url;
Node.js
app.all('*',function(req,res,next)
{
if (!req.get('Origin')) return next();
res.set('Access-Control-Allow-Origin','http://myapp.com');
res.set('Access-Control-Allow-Methods','GET,POST');
res.set('Access-Control-Allow-Headers','X-Requested-With,Content-Type');
if ('OPTIONS' == req.method) return res.send(200);
next();
});
I want to add CORS support to my server
For simple CORS requests, the server only needs to add the following header to its response:
Access-Control-Allow-Origin: *
There are some more headers and settings involved if you want to support verbs other than GET/POST, custom headers, or authentication. You can learn more about these options in theUsing CORS tutorial on HTML5 Rocks.
If you want the TL;DR version, take a look at the flowchart for implementing CORS support.
If you’d like to learn more about implementing CORS for a specific platform, follow one of the links below:
Extremely helpful info specifically the last part 🙂 I care for such information a
lot. I was seeking this certain information for a very long time.
Thank you and good luck.
blog loading? I’m trying to determine if its a problem
on my end or if it’s the blog. Any responses would be greatly appreciated.
I truly appreciate individuals like you! Take care!!
starting my own weblog and was wondering what all is required to get set up?
I’m assuming having a blog like yours would cost a pretty penny?
I’m not very web smart so I’m not 100% sure. Any recommendations or advice would be greatly
appreciated. Thanks
extra about your article on AOL? I need an expert in this house to
unravel my problem. May be that’s you! Having a look forward to
peer you.
on this. And he in fact bought me dinner simply because I discovered it for him…
lol. So allow me to reword this…. Thanks for the meal!!
But yeah, thanx for spending time to discuss this topic here on your internet site.
I will recommend this blog!
from Atascocita Texas! Just wanted to tell you keep up the great job!
team of volunteers and starting a new project in a community in the same niche.
Your blog provided us useful information to work on. You have done a extraordinary job!
It’s the little changes which will make the biggest
changes. Many thanks for sharing!
your posts! Carry on the great work!
do it please help out.