AngularJS控制器与parse.com登录

时间:2016-05-27 14:24:12

标签: javascript angularjs cordova parse-platform

当我在未找到的控制器中执行此代码时:

的index.html

<!DOCTYPE html>
<html ng-app="pfcAPP">

<head>

    <body>
    <title>pfcAPP</title>
</head>
<body>

<div data-role="page">
            <div ng-class="{ 'alert': flash, 'alert-success': flash.type === 'success', 'alert-danger': flash.type === 'error' }" ng-if="flash" ng-bind="flash.message"></div>
            <div ui-view></div>
</div>

    <!-- include Parse-Server files -->
    <script type="text/javascript" src="js/parse-1.6.14.min.js"></script>
    <!-- include Angular files -->
    <script src="//code.angularjs.org/1.2.20/angular.js"></script>
<!-- include APP files -->
    <script type="text/javascript" src="files/app/app.js"></script>      


</body>

</html>

app.js

    console.log('AppController');
   angular.module('APP',[])
    .run(run);

function run() {
    // keep user logged in after page refresh
    Parse.initialize("APPid","masterkey");
    Parse.serverURL = 'http://pfc:1337/parse';
    Parse.User.logIn('luisbg', 'test', {
        success: function(user) {
            // Do stuff after successful login.
            console.log(user);
        },
        error: function(user, error) {
            // The login failed. Check error to see why.
            console.log(error);
        }
    });

}

但如果我从控制器中执行此代码,则会找到。

Parse.User.logIn('luisbg', 'test', {
                success: function (user) {
                  //  console.log(user);
                },
                error: function(user,error) {
                    console.log(error);
                }
            });

我收到了这个错误:

parse-1.6.14.min.js:15 POST http://192.168.2.103:3000/proxy/http%3A%2F%2Fpfc%3A1337%2Fparse%2Flogin 404 (Not Found) 
(index):120 s {code: 107, message: "Received an error with invalid JSON from Parse: Cannot GET /parse/login/parse/login↵"}

我已经为ui.router更改了nGroute,并且我已经探测过在其他控制器中执行此代码,并且我在其他控制器中遇到了同样的问题。

如果我把代码放出角度模块,我会没事的。

    console.log('AppController');
Parse.initialize("APPid","masterkey");
        Parse.serverURL = 'http://pfc:1337/parse';
        Parse.User.logIn('luisbg', 'test', {
            success: function(user) {
                // Do stuff after successful login.
                console.log(user);
            },
            error: function(user, error) {
                // The login failed. Check error to see why.
                console.log(error);
            }
        });
       angular.module('APP',[])
        .run(run);

    function run() {
        // keep user logged in after page refresh


    }

使用此代码我可以在解析时登录或注册,但是当我在角度模块中使用时,它使用其他URL来获取登录:

GET / parse / login / parse / login而不是GET / parse / login

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我只在APACHE SERVER中执行了没有phonegap的应用程序,一切正常。

我会继续寻找问题