Javascript Foursquare返回';无访问控制允许原点';报头存在错误
我正在给foursquare OAuth URL打GET电话。浏览器控制台打印以下错误Javascript Foursquare返回';无访问控制允许原点';报头存在错误,javascript,angularjs,xmlhttprequest,foursquare,Javascript,Angularjs,Xmlhttprequest,Foursquare,我正在给foursquare OAuth URL打GET电话。浏览器控制台打印以下错误 XMLHttpRequest cannot load https://foursquare.com/oauth2/authenticate?client_id=DF4I1TGNVHAM40PDLOHZQZ…onse_type=code&redirect_uri=http://localhost:9000/auth/foursquare/callback. No 'Access-Control-Allo
XMLHttpRequest cannot load https://foursquare.com/oauth2/authenticate?client_id=DF4I1TGNVHAM40PDLOHZQZ…onse_type=code&redirect_uri=http://localhost:9000/auth/foursquare/callback. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
以下是进行调用的代码段:
$http.get(url).success(function(data,status,headers,config){
});
但如果我将一个按钮链接到此url,浏览器会将我带到身份验证页面
这有什么区别?当URL链接到某个按钮时,它为什么工作?当对该URL进行GET调用时,它为什么不工作?Ajax不允许从一个域向另一个域发出请求,除非服务器提供访问控制允许源(CORS)头。允许在域之间进行链接 Mozilla提供了一些关于什么是允许的,什么是不允许的好信息
- 通常允许跨源写入。例如链接、重定向和表单订阅。某些很少使用的HTTP请求需要飞行前处理
- 通常允许跨源嵌入,例如图像、脚本
- 通常不允许跨源读取,例如ajax调用