2

Angularjs v. 1.2.0rc3 with phonegap 3.1 and django-rest-framework

When posting data to my API (login form) I am getting status 200 in angularjs no matter if I authenticate with proper credentials etc. Even though I simply return HTTP_400 in the API view as in the example below, angularjs thinks this is a HTTP_200 status code. I am sure the backend API returns HTTP_400 which works fine when using local http server. I can also confirm this by debugging the api view.

Here's the example code. Django Rest Framework code:

class LoginView(APIView):
    def post(self, request):
        return Response({}, status=status.HTTP_400_BAD_REQUEST)

and my angularjs controller:

$scope.login = function () {
    $http.post(API_URL, $scope.loginUser).then(
        function(response) {
            console.log('STATUS : ' + response.status);
            console.log('request OK');
        },
        function() {
            console.log('request is NOT OK');
        )};

As far as I know phonegap uses a local file:// protocol so there should be no CORS related problem ?

When the same on chrome browser, I get Origin file:// is not allowed by Access-Control-Allow-Origin. Adding --disable-web-security flag to chrome startup script eliminates this problem but it does not solve the "always 200 status code" for phonegap.

Testing on android 2.3 & phonegap 3.1 & angularjs 1.2.0rc3

4

2 に答える 2

0

最新 (バージョン 1.2.9) の AngularJS バージョンにアップグレードします。現在解決されています。

于 2014-01-23T15:04:08.383 に答える