Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49220

Cross-Origin Request Blocked with POST But working fine with req on Browser but on device not working

$
0
0

@hitubansal wrote:

I am trying to build an application using ionic. I am using this code

var req =
{
method: 'POST',
url: API_END_POINT + "/accounts/login",
data: this.toparams(myobject),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}

                $http(req).
                success(function(data, status, headers, config)
                {
                   if(data.result = 'success') {
            console.log('Success', data);
            deferred.resolve(data);
        } else {
            deferred.resolve(0);
        }
                }).
                error(function(data, status, headers, config)
                {
                    console.error('ERR');
 deferred.resolve(0);
                });

        return deferred.promise;

}

This is working fine on browsers but not on device ..

Even if i tired using this method

var link = API_END_POINT +"/accounts/login";

$http.post(link, {username : $scope.data.username,password:$scope.data.password}).then(function (res){
$scope.response = res;
});
This gives me CORS error on browser.

Any idea ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>