XMLHttpRequest无法加载https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri= [英] XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=

查看:155
本文介绍了XMLHttpRequest无法加载https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用password-facebook模块将我的应用程序的facebook登录集成到nodejs,angularjs中.

I am trying to integrate facebook login for my app in nodejs, angularjs using passport-facebook module.

我可以在没有angularjs的情况下整合Facebook身份验证,但是当我使用angular http.get('/auth/facebook')时 我遇到错误了

I can intergrate facebook authentication without angularjs, but when i use angular http.get('/auth/facebook') i am getting below error

XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%…%2Flocalhost%3A1439%2Fauth%2Ffacebook%2Fcallback&client_id=xxxxxxxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1439' is therefore not allowed access.
app.js:153 err

下面是我的角度代码

var headers = {
                'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
                'Content-Type': 'text/html'
            };
    $scope.fblogin=function(){
        // $window.location.href='/auth/facebook';
        $http({
         url:'/auth/facebook',
        method:'GET',
       headers: headers
        }).success(function(data){
            console.log(data);
        }).error(function(){
            console.log('err');
        });
    };

pp.config(['$routeProvider','$httpProvider',
  function($routeProvider,$httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        $httpProvider.defaults.headers.common = 'Content-Type: application/json';
        delete $httpProvider.defaults.headers.common['X-Requested-With'];

NodeJs

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

**注意:**我已尝试更改$ http.get()的多个标头更改

**Note:**I have tried changing multiple header changes for $http.get()

推荐答案

解决方案:

链接https://www.facebook.com/dialog/oauth?...并非旨在将其称为ajax,因为它必须将用户重定向到Facebook登录页面(因此,当您通过ajax进行调用时,则无法进行重定向).

The link https://www.facebook.com/dialog/oauth?... is not designed for calling it as ajax because it must REDIRECT user to facebook login page (so when you call it by ajax then redirect is impossible).

代替make ajax请求,只需准备html适当的元素:

Instead of make ajax request just prepare in html proper element:

<a href="https://www.facebook.com/dialog/oauth?..." > ... </>

这有效:)

这篇关于XMLHttpRequest无法加载https://www.facebook.com/dialog/oauth?response_type=code&amp;redirect_uri=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆