首先低版本浏览器是不支持的,我从网上搜的是[IE8、Firefox 3.5 及其以后的版本、Chrome浏览器、Safari 4 等已经实现了]
下面主要是针对服务器端设置Access-Control-Allow-Origin
[php]
header( 'Access-Control-Allow-Origin:*' );
header( 'Access-Control-Allow-Origin:http://A.abc.com' );
[java]
Response.AddHeader("Access-Control-Allow-Origin", "*");
header( 'Access-Control-Allow-Origin:http://A.abc.com,http://B.abc.com' );
[html]
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta http-equiv="Access-Control-Allow-Origin" content="http://A.com">
[nodejs]
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
[nginx]
location / {
add_header Access-Control-Allow-Origin *;
}
[apache]
去掉注释LoadModule headers_module modules/mod_headers.so
conf/extra/httpd-ssl
<VirtualHost>
...
Header add Access-Control-Allow-Origin *
Header add Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header add Access-Control-Allow-Headers "Content-Type"
</VirtualHost>
Access-Control-Allow-Origin *这里的*代表所有都可以访问,如果设置一个或多个域名,说明只能让设置的访问。