2015년 1월 6일 화요일

[AngularJS] Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

Someone please solve my problem :Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
the below code is cors using springs we set to accept:application/json on springs,

my url:http://localhost:8383/menu.html
server urls is:http://192.168.0.10:8080/com.laalsa.api/laalsa/add/category



    var menucategory = angular.module("menucategory", ['myApps']);
    menucategory.config(['$httpProvider', function($httpProvider) {


            $scope.menucategoryfunction = function(menuForm) {
                console.log("+++++++++" + angular.toJson($scope.menuForm));
                var data1 = {
                    category_name: "Hello world"
                };
                var jscon = JSON.stringify('category_name', 'hello world');
                var ssss = JSON.stringify({category_name: 'sandeep kumar jollu'});
                console.log("****" + ssss);

                var promise = $http({
                    "method": "post",
                    "url": "http://192.168.0.10:8080/com.laalsa.api/laalsa/add/category",
                    data:$scope.menuForm,
                   data: {
                        category_name: menuForm.category_name
                    },
                    headers: {
                        "Content-Type": "application/json"
                });

                promise.success(function(data, status, headers, config, statusText) {
                    console.log("success:   " + JSON.stringify(data));
                    console.log("2:   " + JSON.stringify(status));
                    console.log("3:   " + JSON.stringify(headers));
                    console.log("4:   " + JSON.stringify(config));
                    console.log("statusText:   " + JSON.stringify(statusText));
                });
                promise.error(function(data, status, headers, config) {
                    console.log("data:   " + JSON.stringify(data));
                    console.log("status:   " + JSON.stringify(status) + status);
                    console.log("headers:   " + JSON.stringify(headers));
                    console.log("config:   " + JSON.stringify(config));
                });
            };
     }]);


댓글 없음:

댓글 쓰기