0

I am trying to send the registration form data to an api that registers the user and provides the success response. I am getting the following error while try to send the data through $http

/ringleader/www/#!/register:1 XMLHttpRequest cannot load 
http://72.5.146.113/portal-app/API/addRingLeader/?0=f&1=i&10=s&100=c&101=i&…
87=d&88=g&89=%26&9=%3D&90=p&91=r&92=o&93=d&94=u&95=c&96=t&97=%3D&98=S&99=o. 
Response for preflight has invalid HTTP status code 404

Here is my controller

.controller('loginController',function($scope,authService){
$scope.login = function(data){
    authService.login(data).then(function(response){
        console.log(response.status + " ------ "+JSON.stringify(response));
    },function(err){
        if (err) { 
            console.log(err);
        }
    })
}

})

.controller('registerController',function($scope,authService){
$scope.register = function(data){
    authService.register(data).then(function(response){
        console.log(response.status + " ------ "+JSON.stringify(response));
    },function(err){
        if (err) { 
            console.log(err);
        }
    })
}
})

and this is my service

.factory('authService',function($http){
return{
    register : function(data){
        return $http({
            url: 'http://72.5.146.113/portal-app/API/addRingLeader/',
            method: 'POST',
            params: $.param({
                firstname : data.firstname,
                lastname : data.lastname,
                email : data.email,
                mobile : data.mobile,
                password : data.password,
                product : "Social"
            }),
            dataType: "jsonp",
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
    },
    login : function(data){
        return $http({
            url: 'http://72.5.146.113/portal-app/API/signIn/',
            method: 'POST',
            params: $.param(data),
            dataType: "jsonp",
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
    }
}
})

and this is how the response should look like. enter image description here

Sam
  • 67
  • 4
  • 12
  • did u check cors is enabled in server? you can refer this link https://www.html5rocks.com/en/tutorials/cors/ – Nayas Subramanian Jun 19 '17 at 05:33
  • You should check in network whether you are getting Access-Control-Allow-Credentials: true as respone when you send options method – Nayas Subramanian Jun 19 '17 at 05:39
  • https://stackoverflow.com/questions/33660712/angularjs-post-fails-response-for-preflight-has-invalid-http-status-code-404 – Tik Jun 19 '17 at 05:46
  • The server is maintained by third party I don't have access to the server. the CORS is enabled in my browser(chrome). @Nayas Subramanian – Sam Jun 19 '17 at 05:51
  • Is CORS enabled in server? It looks not... – shaochuancs Jun 19 '17 at 05:54
  • Possible duplicate of [AngularJS POST Fails: Response for preflight has invalid HTTP status code 404](https://stackoverflow.com/questions/33660712/angularjs-post-fails-response-for-preflight-has-invalid-http-status-code-404) – shaochuancs Jun 19 '17 at 05:54
  • @Sam you can check whether cors is enabled from network tab. You can see two request calls when u trigger a create in network. In the first response you can see whether Access-Control-Allow-Credentials: true. – Nayas Subramanian Jun 19 '17 at 06:58

0 Answers0