1

While hitting my post api hit i am getting this above mentioned error , i tried a lot by following few of the links but didn't get any output , when i try to solve this error by adding bellow code in my app.js file.

app
  .config(function($httpProvider, $stateProvider, $urlRouterProvider) {
   $httpProvider.defaults.headers.common['Access-Control-Allow-Headers'] = '*';
});

This is how i am hitting my post api :-

$http
         .post(
           'http://www.mastersoftwaretechnologies.com:90/restapi/customer/setaddress/',
           {
            firstname : $scope.data.full_name,
            lastname : $scope.data.last_name,
            street : $scope.data.address,
            city : $scope.data.city_name,
            country_id : $scope.user.country,
            region : $scope.data.state,
            postcode : $scope.data.pin_name,
            telephone : $scope.data.phone_name
           })
         .then(
           function(response) {
            $ionicLoading.hide();
            alert(JSON.stringify(response));
            $scope.data.full_name = '';
            $scope.data.last_name = '';
            $scope.data.address = '';
            $scope.data.city_name = '';
            $scope.user.country = '';
            $scope.data.state = '';
            $scope.data.pin_name = '';
            $scope.data.phone_name
            $state.go('app.paymethod');
           }

Error :- My data is not getting passed to server its going blank.

But when i hit this api from postman the data is getting entered in server and on hit on getaddress api i am getting the same address which i entered in setaddress api (in case of post-man its working but in my device it's not).

Can any body tell me how to resolve this error do i need to add some more headers at my end or do i need to add headers on server end ?

Please provide me some solution.

Thanks.

sid
  • 1,116
  • 1
  • 10
  • 27
  • Hey @Quentine i have seen this thread while my R&D but this thread doesn't help me anywhere thats why i posted this question , can you please tell me where do i need to make changes in my code or at server end i need to add those headers. – sid Oct 23 '15 at 13:16
  • I even try with this sample code $http .post( 'http://www.mastersoftwaretechnologies.com:90/restapi/customer/setaddress/', "firstname=" + encodeURIComponent($scope.data.full_name) + "&lastname=" + encodeURIComponent($scope.data.last_name) + "&street=" + encodeURIComponent($scope.data.address)) – sid Oct 23 '15 at 14:37
  • Finally i got my answer , http://stackoverflow.com/questions/24710503/how-do-i-post-urlencoded-form-data-with-http-in-angularjs/24964658#24964658 , Thanks to @allenhwkim for his awesome answer. – sid Oct 26 '15 at 05:23

0 Answers0