Http post in angulare Js cross origen blocked


#1

Hi All,
i am developing simple login form for mobile app and i am new to this ionic
Same post method working through fiddler and not working from ionic angular cross origen blocked error throwing where i need set properties.

Please check the below code.

.controller(‘LoginCtrl’, function ($scope, $http) {
$scope.login = function (user) {
alert(‘hello’);
var userdetails = { grant_type: “password”, username: user.username, password: user.password };
console.log(userdetails);

    $http({
        url: user.url + "/Token",
        method: "POST",
        data: userdetails,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).success(function (data, status, headers, config) {
        console.log(data);
    }).error(function (data, status, headers, config) {
        alert('error found');
    });

});

Thanks inadvance
Janardana B


#2

Add

<?php header('Access-Control-Allow-Origin: *'); ?>

To your php file (if you are using php for the login process).


#3

Have you tried setting $sce?

This is angular’s way of dealing with cross domain issues.
https://docs.angularjs.org/api/ng/service/$sce#getTrustedResourceUrl