我正在对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-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调用时它不起作用?
除非服务器提供Access-Control-Allow-Origin(CORS)标头,否则Ajax不允许从一个域到另一个域的请求。域之间的链接是允许的。
Mozilla对于允许和禁止的内容有一些很好的信息。https://developer.mozilla.org/zh-CN/docs/Web/Security/Same-origin_policy#Cross-origin_network_access
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句